Skip to content

Commit

Permalink
fixes #1518 Disconnect during negotiation breaks listener
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Oct 17, 2021
1 parent 8d7dcb6 commit 9248ed7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
21 changes: 13 additions & 8 deletions src/sp/transport/ipc/ipc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2020 Staysail Systems, Inc. <[email protected]>
// Copyright 2021 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
// Copyright 2019 Devolutions <[email protected]>
//
Expand All @@ -10,7 +10,6 @@
//

#include <stdio.h>
#include <stdlib.h>

#include "core/nng_impl.h"

Expand Down Expand Up @@ -251,8 +250,8 @@ ipc_pipe_neg_cb(void *arg)
nni_mtx_unlock(&p->ep->mtx);
return;
}
// We have both sent and received the headers. Lets check the
// receive side header.
// We have both sent and received the headers. Let's check the
// receiver.
if ((p->rx_head[0] != 0) || (p->rx_head[1] != 'S') ||
(p->rx_head[2] != 'P') || (p->rx_head[3] != 0) ||
(p->rx_head[6] != 0) || (p->rx_head[7] != 0)) {
Expand All @@ -262,7 +261,7 @@ ipc_pipe_neg_cb(void *arg)

NNI_GET16(&p->rx_head[4], p->peer);

// We are all ready now. We put this in the wait list, and
// We are ready now. We put this in the wait list, and
// then try to run the matcher.
nni_list_remove(&ep->neg_pipes, p);
nni_list_append(&ep->wait_pipes, p);
Expand All @@ -272,7 +271,13 @@ ipc_pipe_neg_cb(void *arg)
return;

error:

// If the connection is closed, we need to pass back a different
// error code. This is necessary to avoid a problem where the
// closed status is confused with the accept file descriptor
// being closed.
if (rv == NNG_ECLOSED) {
rv = NNG_ECONNSHUT;
}
nng_stream_close(p->conn);
// If we are waiting to negotiate on a client side, then a failure
// here has to be passed to the user app.
Expand Down Expand Up @@ -347,7 +352,7 @@ ipc_pipe_recv_cb(void *arg)

if ((rv = nni_aio_result(rx_aio)) != 0) {
// Error on receive. This has to cause an error back
// to the user. Also, if we had allocated an rx_msg, lets
// to the user. Also, if we had an allocated rx_msg, lets
// toss it.
goto error;
}
Expand Down Expand Up @@ -406,7 +411,7 @@ ipc_pipe_recv_cb(void *arg)
}
}

// Otherwise we got a message read completely. Let the user know the
// Otherwise, we got a message read completely. Let the user know the
// good news.

aio = nni_list_first(&p->recv_q);
Expand Down
14 changes: 10 additions & 4 deletions src/sp/transport/tcp/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// found online at https://opensource.org/licenses/MIT.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -259,8 +258,8 @@ tcptran_pipe_nego_cb(void *arg)
nni_mtx_unlock(&ep->mtx);
return;
}
// We have both sent and received the headers. Lets check the
// receive side header.
// We have both sent and received the headers. Let's check the
// receiver.
if ((p->rxlen[0] != 0) || (p->rxlen[1] != 'S') ||
(p->rxlen[2] != 'P') || (p->rxlen[3] != 0) || (p->rxlen[6] != 0) ||
(p->rxlen[7] != 0)) {
Expand All @@ -270,7 +269,7 @@ tcptran_pipe_nego_cb(void *arg)

NNI_GET16(&p->rxlen[4], p->peer);

// We are all ready now. We put this in the wait list, and
// We are ready now. We put this in the wait list, and
// then try to run the matcher.
nni_list_remove(&ep->negopipes, p);
nni_list_append(&ep->waitpipes, p);
Expand All @@ -281,6 +280,13 @@ tcptran_pipe_nego_cb(void *arg)
return;

error:
// If the connection is closed, we need to pass back a different
// error code. This is necessary to avoid a problem where the
// closed status is confused with the accept file descriptor
// being closed.
if (rv == NNG_ECLOSED) {
rv = NNG_ECONNSHUT;
}
nng_stream_close(p->conn);

if ((uaio = ep->useraio) != NULL) {
Expand Down
13 changes: 10 additions & 3 deletions src/sp/transport/tls/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ tlstran_pipe_nego_cb(void *arg)
nni_mtx_unlock(&ep->mtx);
return;
}
// We have both sent and received the headers. Lets check the
// receive side header.
// We have both sent and received the headers. Let's check the
// receiver.
if ((p->rxlen[0] != 0) || (p->rxlen[1] != 'S') ||
(p->rxlen[2] != 'P') || (p->rxlen[3] != 0) || (p->rxlen[6] != 0) ||
(p->rxlen[7] != 0)) {
Expand All @@ -269,7 +269,7 @@ tlstran_pipe_nego_cb(void *arg)

NNI_GET16(&p->rxlen[4], p->peer);

// We are all ready now. We put this in the wait list, and
// We are ready now. We put this in the wait list, and
// then try to run the matcher.
nni_list_remove(&ep->negopipes, p);
nni_list_append(&ep->waitpipes, p);
Expand All @@ -280,6 +280,13 @@ tlstran_pipe_nego_cb(void *arg)
return;

error:
// If the connection is closed, we need to pass back a different
// error code. This is necessary to avoid a problem where the
// closed status is confused with the accept file descriptor
// being closed.
if (rv == NNG_ECLOSED) {
rv = NNG_ECONNSHUT;
}
nng_stream_close(p->tls);

if ((uaio = ep->useraio) != NULL) {
Expand Down

0 comments on commit 9248ed7

Please sign in to comment.