-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
SSL_poll() should re-issue SSL_shutdown() when object is #27909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
in shutting_down state. This is the scenario which requires proposed twek. The client application uses event loop. The event loop invokes callbacks to serve the events reported by SSL_poll(). The recv() callback receives all data on its last stream. The recv() callback invokes SSL_shutdown() on connection object which owns the stream. The regular shutdown can not progress here because there is stream still attached. The recv() callback returns and hints event loop the stream object can be destroyed now. event loop then does SSL_free() on stream object. Once stream object is freed the event loop calls SSL_poll() again. Here we should call SSL_shutdown() on connection which used to own stream. The connection shuuld be able to proceed to ossl_quic_channel_local_close() which schedules CONNECTION_CLOSE notification. This makes the connection unstuck. Fixes openssl/project#1105
I think this is actually a bug in the demo poll server application. There is IMO missing a SSL_handle_events() call somewhere - either in the poll loop which might be unnecessary or at least after SSL_free() is called on the stream object. Re-doing the SSL_shutdown() call implicitly in SSL_poll() seems wrong to me but what do others think? @mattcaswell @nhorman |
So in this case we need to update a documentation that event loop must call to SSL_poll() and
The |
I'm afraid If we want to fix application, then event loop must monitor connections which have shutdown in progress. For those connections the event loop must ensure to call SSL_shutdown() periodically. |
I agree with @t8m that calling SSL_shutdown from within SSL_poll feels at least counter-intuitive, but as for whats going on, I can't currently say, as I've not looked closely enough at the code. @Sashan I think we were going to cover this tomorrow before your holiday yes? I'll try to look at this closely prior to that so I can speak intelligently about it |
Ah, you're right. So actually the application is supposed to repeat SSL_shutdown() calls once it intends to shutdown the connection. See this excerpt from the manpage https://docs.openssl.org/master/man3/SSL_shutdown/#shutdown-mode : RFC compliant shutdown mode This is the default behaviour. The shutdown process may take a period of time up to three times the current estimated RTT to the peer. It is possible for the closure process to complete much faster in some circumstances but this cannot be relied upon. In blocking mode, the function will return once the closure process is complete. In nonblocking mode, SSL_shutdown_ex() should be called until it returns 1, indicating the closure process is complete and the connection is now fully shut down. |
yes exactly. The problem is the non-blocking variant of |
This is an application bug. An application must use |
In this case SSL_poll() API should not allow to set indefinite time out all. I think. IMO we should prevent applications to pass With current state of affairs allowing indefinite poll just allows applications to shoot their knee when they need to use SSL_shutdown(). SSL_shitdown() just does not play well with indefinite SSL_poll(). And it's nowhere documented. I'd like to come up with a solution that creates the least surprises for applications that use |
I agree this a bug in application. The question is how it should get fixed:
to be honest I'm not able to think of any drawback in current approach. It seems to work well with SSL_poll() that blocks indefinitely. |
in shutting_down state.
This is the scenario which requires proposed twek.
The client application uses event loop. The event loop invokes callbacks to serve the events reported by SSL_poll().
The recv() callback receives all data on its last stream.
The recv() callback invokes SSL_shutdown() on connection object which owns the stream. The regular shutdown can not progress here because there is stream still attached.
The recv() callback returns and hints event loop the stream object can be destroyed now. event loop then does SSL_free() on stream object.
Once stream object is freed the event loop calls SSL_poll() again. Here we should call SSL_shutdown() on connection which used to own stream. The connection shuuld be able to proceed to ossl_quic_channel_local_close() which schedules CONNECTION_CLOSE notification. This makes the connection unstuck.
Fixes openssl/project#1232
Checklist