Subject: Re: bug#22789: 25.1.50; In last master build https connections stop working

From: Alain Schneble <[email-masked]>
Date: Mon, 7 Mar 2016 18:20:20 +0100

Eli Zaretskii <[email-masked]> writes:

>> From: Alain Schneble <[email-masked]>
>> CC: <[email-masked]>, <[email-masked]>, <[email-masked]>
>> Date: Mon, 7 Mar 2016 09:49:00 +0100
>>
>> - So there /is/ a dependency between these calls.  Unfortunately, I
>>   couldn't see that ioctlsocket returns with WSAEINVAL in the scenarios
>>   I tried.
>
> Yes, I know about this gotcha.  It's just that it never produced any
> problems, and I never was able to see the ioctlsocket call fail with
> WSAEINVAL.

As said, I didn't see WSAEINVAL as well with the current implementation.

>>   Could it be a multi-threading issue then?  Multiple threads
>>   accessing the same socket...
>
> Not sure I follow -- are you trying to explain why ioctlsocket doesn't
> fail as expected, or are you trying to explain some other phenomenon?

Both.  1) I expected it to (sometime) fail but didn't see it.  2) The
arbitrary gnutls_handshake failures I observed seem like the socket's
state is getting corrupted.

Do you agree that WSAEventSelect is called from the reader thread and
the ioctlsocket is called from the main thread?  And AFAIK, these
functions are not thread safe...  So I suspect that we ran into a
multi-threading issue here, which corrupted the socket.  And may have
lead to the above mentioned issues.

>>   I don't see how both threads are synchronized.
>
> The synchronization is between reader_thread and sys_select.  The
> latter runs in the main (a.k.a. "Lisp") thread, the same thread where
> sys_write is called.

This is how I understood it as well...

>>   The patch I sent would synchronize them through the FILE_CONNECT
>>   flag, I think.  Did I miss something?
>
> Well, that's not really "thread synchronization", but see my comments
> and questions there.

Yes, you are right.  I just meant that both threads no longer will call
WSAEventSelect and ioctlsocket at the same time with the proposed patch.
And this is a kind of "synchronization".