Skip to content

Commit

Permalink
timeout counts as pernmanently unusable close
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Green <[email protected]>
  • Loading branch information
Andy Green committed Apr 12, 2015
1 parent 7fb366a commit 408f537
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/libwebsockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context,

old_state = wsi->state;

if (wsi->socket_is_permanently_unusable || reason == LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY)
if (wsi->socket_is_permanently_unusable ||
reason == LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY)
goto just_kill_connection;

switch (old_state) {
Expand Down
14 changes: 12 additions & 2 deletions lib/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ libwebsocket_service_timeout_check(struct libwebsocket_context *context,
*/
if (sec > wsi->pending_timeout_limit) {
lwsl_info("TIMEDOUT WAITING on %d\n", wsi->pending_timeout);
/*
* Since he failed a timeout, he already had a chance to do
* something and was unable to... that includes situations like
* half closed connections. So process this "failed timeout"
* close as a violent death and don't try to do protocol
* cleanup like flush partials.
*/
wsi->socket_is_permanently_unusable = 1;
libwebsocket_close_and_free_session(context,
wsi, LWS_CLOSE_STATUS_NOSTATUS);
return 1;
Expand Down Expand Up @@ -478,8 +486,10 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
/* the guy requested a callback when it was OK to write */

if ((pollfd->revents & LWS_POLLOUT) &&
(wsi->state == WSI_STATE_ESTABLISHED || wsi->state == WSI_STATE_HTTP2_ESTABLISHED || wsi->state == WSI_STATE_HTTP2_ESTABLISHED_PRE_SETTINGS ||
wsi->state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE) &&
(wsi->state == WSI_STATE_ESTABLISHED ||
wsi->state == WSI_STATE_HTTP2_ESTABLISHED ||
wsi->state == WSI_STATE_HTTP2_ESTABLISHED_PRE_SETTINGS ||
wsi->state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE) &&
lws_handle_POLLOUT_event(context, wsi, pollfd)) {
lwsl_info("libwebsocket_service_fd: closing\n");
goto close_and_handled;
Expand Down

0 comments on commit 408f537

Please sign in to comment.