Router: fixing crash after WebSocket processing.

After WebSocket processing, the application port was released with incorrect
reason ("got request"), unnecessarily decrementing the active request counter.

The assertion was triggered only on application removal; a test was added
for this case.
This commit is contained in:
Max Romanov 2021-01-28 17:13:52 +03:00
parent 3855f1c032
commit e4e444b827
3 changed files with 35 additions and 1 deletions

View file

@ -97,6 +97,13 @@ a memory leak occurring in the router process when serving a file larger than
</para>
</change>
<change type="bugfix">
<para>
the router process could crash while removing or reconfiguring an application
that uses WebSocket.
</para>
</change>
</changes>

View file

@ -3796,7 +3796,10 @@ nxt_router_response_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg,
nxt_buf_chain_add(&b, nxt_http_buf_last(r));
req_rpc_data->rpc_cancel = 0;
req_rpc_data->apr_action = NXT_APR_GOT_RESPONSE;
if (req_rpc_data->apr_action == NXT_APR_REQUEST_FAILED) {
req_rpc_data->apr_action = NXT_APR_GOT_RESPONSE;
}
nxt_request_rpc_data_unlink(task, req_rpc_data);

View file

@ -63,6 +63,9 @@ class TestASGIWebsockets(TestApplicationPython):
key
), 'key'
# remove "mirror" application
self.load('websockets/subprotocol')
def test_asgi_websockets_subprotocol(self):
self.load('websockets/subprotocol')
@ -92,6 +95,27 @@ class TestASGIWebsockets(TestApplicationPython):
sock.close()
def test_asgi_websockets_mirror_app_change(self):
self.load('websockets/mirror')
message = 'blah'
_, sock, _ = self.ws.upgrade()
self.ws.frame_write(sock, self.ws.OP_TEXT, message)
frame = self.ws.frame_read(sock)
assert message == frame['data'].decode('utf-8'), 'mirror'
self.load('websockets/subprotocol')
self.ws.frame_write(sock, self.ws.OP_TEXT, message)
frame = self.ws.frame_read(sock)
assert message == frame['data'].decode('utf-8'), 'mirror 2'
sock.close()
def test_asgi_websockets_no_mask(self):
self.load('websockets/mirror')