Welcome! Log In Create A New Profile

Advanced

Re: nginx for Windows - WSASend() socket error 10057

Yury Shpakov
February 13, 2020 04:50PM
Extra info:

C:\WINDOWS\system32>netstat /nabo | grep -A 1 ":9000\b"
TCP 0.0.0.0:9000 0.0.0.0:0 LISTENING 34540
[nginx.exe]

________________________________
From: nginx-devel <nginx-devel-bounces@nginx.org> on behalf of Yury Shpakov <yshpakov@hotmail.com>
Sent: Thursday, February 13, 2020 4:45 PM
To: Sergey Brester <serg.brester@sebres.de>
Cc: nginx-devel@nginx.org <nginx-devel@nginx.org>
Subject: Re: nginx for Windows - WSASend() socket error 10057

Hi Sergey,


I reconfigured the config file as follows:

=== === ===
#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


mail {
server_name localhost;
auth_http localhost:9000/cgi-bin/nginxauth.cgi;
# auth_http none;

smtp_auth none;
# smtp_auth login plain cram-md5;
# smtp_capabilities "SIZE 10485760" ENHANCEDSTATUSCODES 8BITMIME DSN;
xclient off;

server {
listen 8025;
protocol smtp;
proxy on;
proxy_pass_error_message on;
}
}

http {
server {
listen 9000;

location /cgi-bin/nginxauth.cgi {
add_header Auth-Status OK;
add_header Auth-Server 127.0.0.2; # backend ip
add_header Auth-Port 143; # backend port
return 204;
}
}
}
=== === ===

And now it's responding on port 9000 as expected:

=== === ===
C:\WINDOWS\system32>curl -H "Auth-Method: plain" -H "Auth-User: user" -H "Auth-Pass: pwd" -H "Auth-Protocol: imap" -H "Auth-Login-Attempt: 1" -i http://127.0.0.1:9000/cgi-bin/nginxauth.cgi
HTTP/1.1 204 No Content
Server: nginx/1.17.9
Date: Thu, 13 Feb 2020 21:30:54 GMT
Connection: keep-alive
Auth-Status: OK
Auth-Server: 127.0.0.2
Auth-Port: 143
=== === ===

However I'm still experiencing the same issue (in log file):

=== === ===
2020/02/13 16:29:24 [notice] 35048#26192: signal process started
2020/02/13 16:29:34 [error] 31732#22720: *1 WSASend() failed (10057: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied) while in http auth state, client: 127.0.0.1, server: 0.0.0.0:8025
=== === ===

Tried under both admin and regular user.

Any further ideas how to get it fixed please?


Thank you,
Yury
________________________________
From: Sergey Brester <serg.brester@sebres.de>
Sent: Wednesday, February 12, 2020 1:51 PM
To: Yury Shpakov <yshpakov@hotmail.com>
Cc: nginx-devel@nginx.org <nginx-devel@nginx.org>
Subject: Re: nginx for Windows - WSASend() socket error 10057


I answered inline...

12.02.2020 18:59, Yury Shpakov wrote:

Hi Sergey,


Thank you for you response.

I tried netstat /nabo and I don't see any reference to port 9000 at all.
So a problem is to make nginx to listen on port 9000 (as server)?
Or nginx is not listening on port 9000 but rather sending requests to port 9000 (as client)?
With setting of `auth_http`, you are defining an URL to the service responsible for authentication (and upstream choice).
Of course then you should have something that would response to the auth-requests (your own upstream, or some nginx location, or some "foreign" http-server).

See https://docs.nginx.com/nginx/admin-guide/mail-proxy/mail-proxy/ for more examples.
Maybe it's easier not to use auth_http at all? I was trying to remove it from configuration file but nginx was not happy.

I have my own auth-module so I don't know how it can be solved in stock-nginx without this directive.

Take a look here - https://serverfault.com/questions/594962/nginx-understanding-the-purpose-of-auth-http-imap-proxy - you can use some nginx location (and internal URL to same nginx instance) to specify that.

Anyway it is recommended to use some auth (on nginx side), because it'd preserve the resources of mail-servers, allow you to authenticate email clients with same user/password for all mail-servers (smtp, imap, pop3, etc) as well as the same user/pwd as for some other http-services. And it is used to choose an upstream server (if multiple) for the email processing.

At this point I don't need any authentication. I was told by my boss to use nginx for load testing of our service sending emails (SMTP client). I've got some SMTP Server and nginx would be used as SMTP proxy because it allows to set up delays.
Well, an auth request to some nginx-location would allow you to set up delays even on authentication phase.
And take into account that I REMOVED "--with-http_ssl_module" from parameters when I was building nginx.

And you advised to download some nginx.exe files but I believe they were built without "--with-mail" parameter (which I need).
Although, it was compiled with "--with-mail" (you can see all parameters in provided GH-linkhttps://github.com/sebres/nginx/releases/tag/release-1.13..0)
But it would not help, because basically your issue seems to be the configuration (not the nginx.exe).

Thank you,
Yury

________________________________
From: Sergey Brester <serg.brester@sebres.de>
Sent: Wednesday, February 12, 2020 7:38 AM
To: nginx-devel@nginx.org <nginx-devel@nginx.org>
Cc: Yury Shpakov <yshpakov@hotmail.com>
Subject: Re: nginx for Windows - WSASend() socket error 10057

It looks like your service defined in auth_http doesn't answer (or no listener on 127.0.0.1 port 9000?)...

try netstat (in cmd as admin):

netstat /nabo
netstat /nabo | grep -A 1 ":9000\b"

and check whether the listener on port 9000 is bound to 127.0.0.1 (or it is 0.0.0.0 only?) and it is the process you expect to see there (can be "reserved" by some other windows-service).

additionally try to telnet or curl it:

curl -H "Auth-Method: plain" -H "Auth-User: user" -H "Auth-Pass: pwd" -H "Auth-Protocol: imap" -H "Auth-Login-Attempt: 1" -i http://127.0.0.1:9000/cgi-bin/nginxauth.cgi

if it does not answer, make another attempt by replace 127.0.0.1 with 0.0.0..0 (or a host-name).

If it answers - see whether it is the expected response (some examples of good and bad responses are described in http://nginx.org/en/docs/mail/ngx_mail_auth_http_module.html).

But I guess if WSASend fails, it would probably (unexpected) reject the connection during the send (or even connect) process.
It can be also invalid (unexpected) content-length in keep-alive connect to auth-upstream - so send but still receive is expected (or vice versa).

Also follow this forum topic addressing similar issue: https://forum.nginx.org/read.php?2,257206,257207#msg-257207

Anyway it doesn't look to me like an issue of nginx (regardless windows or not), but you can also try some other ready build (for example on my GHhttps://github.com/sebres/nginx/releases/tag/release-1.13.0 - nginx.ziphttps://github.com/sebres/nginx/files/2246440/nginx.zip, where it works well).

Regards,
Sergey

12.02.2020 03:01, Yury Shpakov wrote:

Hi there,
Trying to make nginx work as SMTP server and/or SMTP proxy. Done everything according to:
http://nginx.org/en/docs/howto_build_on_win32.html
But excluded (don't care about SSL at this point so don't want to install/configure Perl now):
--with-openssl=objs/lib/openssl-master \
--with-openssl-opt=no-asm \
--with-http_ssl_module \
And added:
--with-mail
nmake was successful and nginx.exe was created.
However nginx.exe keeps failing with the error:
WSASend() failed (10057: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied) while in http auth state, client: 127.0.0.1, server: 0.0.0.0:8025
Windows API says the following about this error:

WSAENOTCONN
10057

Socket is not connected.
A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using sendtohttps://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-sendto) no address was supplied. Any other type of operation might also return this error—for example, setsockopthttps://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-setsockopt setting SO_KEEPALIVEhttps://docs.microsoft.com/en-us/windows/desktop/winsock/so-keepalive if the connection has been reset.
https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2
Windows Sockets Error Codes (Winsock2.h) - Win32 apps | Microsoft Docshttps://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2
Return code/value Description; WSA_INVALID_HANDLE 6: Specified event object handle is invalid. An application attempts to use an event object, but the specified handle is not valid.
docs.microsoft.com
Managed to debug your code in VS 2010 a little bit but it's brutal C so it's hard to figure your code out. And this debugger doesn't show you any local variables values.
Any recommendation for me to make it work?
Tried to play with config (commenting/uncommenting):
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
mail {
server_name localhost;
auth_http localhost:9000/cgi-bin/nginxauth.cgi;
# auth_http none;
smtp_auth none;
# smtp_auth login plain cram-md5;
# smtp_capabilities "SIZE 10485760" ENHANCEDSTATUSCODES 8BITMIME DSN;
xclient off;
server {
listen 8025;
protocol smtp;
proxy on;
proxy_pass_error_message on;
}
}
Tried both under a regular user and under admin. Tried on 25, 1025 and 8025 ports.
Thank you,
Yury


_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org<mailto:nginx-devel@nginx.org>http://mailman.nginx.org/mailman/listinfo/nginx-devel
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

nginx for Windows - WSASend() socket error 10057

Yury Shpakov 1350 February 11, 2020 09:04PM

Re: nginx for Windows - WSASend() socket error 10057

Sergey Brester 316 February 12, 2020 07:40AM

Re: nginx for Windows - WSASend() socket error 10057

Yury Shpakov 173 February 12, 2020 01:00PM

Re: nginx for Windows - WSASend() socket error 10057

Sergey Brester 215 February 12, 2020 01:52PM

Re: nginx for Windows - WSASend() socket error 10057

Yury Shpakov 163 February 13, 2020 04:46PM

Re: nginx for Windows - WSASend() socket error 10057

Yury Shpakov 192 February 13, 2020 04:50PM

Re: nginx for Windows - WSASend() socket error 10057

Sergey Brester 202 February 14, 2020 06:00AM

Re: nginx for Windows - WSASend() socket error 10057

Yury Shpakov 472 February 14, 2020 06:10PM

Re: nginx for Windows - WSASend() socket error 10057

Yury Shpakov 158 February 25, 2020 08:00PM

Re: nginx for Windows - WSASend() socket error 10057

Sergey Brester 152 February 26, 2020 04:52AM

Re: nginx for Windows - WSASend() socket error 10057 Attachments

Yury Shpakov 137 February 26, 2020 03:38PM

Re: nginx for Windows - WSASend() socket error 10057 Attachments

Sergey Brester 170 February 27, 2020 05:22AM

Re: nginx for Windows - WSASend() socket error 10057

Maxim Dounin 142 February 27, 2020 06:48AM

Re: nginx for Windows - WSASend() socket error 10057

Dipl. Ing. Sergey Brester 192 February 27, 2020 08:30AM

Re: nginx for Windows - WSASend() socket error 10057 Attachments

Yury Shpakov 142 February 27, 2020 02:42PM

Re: nginx for Windows - WSASend() socket error 10057

Maxim Dounin 396 February 28, 2020 08:28AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 220
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready