Skip to content

Conversation

@xv-ian-c
Copy link
Contributor

Description

I have observed evidence of a rare case where the server process exited due to an issue with a specific TCP connection. First:

recvfrom(22, 0x7f7dc8033830, 1500, 0, NULL, NULL) = -1 ECONNRESET (Connection reset by peer)

followed by:

sendto(22, "..."..., 265, MSG_NOSIGNAL, NULL, 0) = -1 EPIPE (Broken pipe)

which causes the inside I/O loop to exit:

Error: Inside IO loop exited

Caused by:
    0: Inside data handling error
    1: WolfSSL Error: Fatal: code: -308, what: error state on socket
    2: Fatal: code: -308, what: error state on socket

I think this scenario can arise if there is traffic inflight inside->outside at just the moment the socket is going away.

I've not been able to reproduce at will. The first two commits are based on code inspection.

The third commit is more of a cleanup given that all callers ignore the result of Connection::disconnect already.

Motivation and Context

Issues with a single connection should not cause the whole server process to exit.

How Has This Been Tested?

E2E

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • The correct base branch is being used, if not main

After e.g.
```
recvfrom(22, 0x7f7dc8033830, 1500, 0, NULL, NULL) = -1 ECONNRESET (Connection reset by peer)
```

the socket is no longer valid for read or write, but we only shutdown the
connection on a return of 0, meaning we subsequently hit:

```
sendto(22, "..."..., 265, MSG_NOSIGNAL, NULL, 0) = -1 EPIPE (Broken pipe)
```

which exits the inside I/O loop with:

```
Error: Inside IO loop exited

Caused by:
    0: Inside data handling error
    1: WolfSSL Error: Fatal: code: -308, what: error state on socket
    2: Fatal: code: -308, what: error state on socket
```
... this could be (and most probably is) a connection specific issue and need
not result in the whole process exiting.

If the error is fatal for the connection then tear it down.
... when sending the goodbye message a failure could happen if the socket (for
a TCP connection) has already been closed by the peer (which is one reason we
might be disconnecting).

Similarly for the `try_shutdown` call which may try to send a TLS close
notification.

All callers already ignore the result of `Connection::disconnect`, so in
practice this is a noop change, but it more closely matches the "just a
courtesy" intention.
@xv-ian-c xv-ian-c merged commit 8730498 into main Nov 22, 2024
11 checks passed
@xv-ian-c xv-ian-c deleted the CVPN-1608-cleanup-tcp-conn branch November 22, 2024 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants