Skip to content
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

Better error hanndling during client & server start, and during handshakes #4790

Conversation

kwvanderlinde
Copy link
Collaborator

@kwvanderlinde kwvanderlinde commented May 23, 2024

Identify the Bug or Feature request

Improves on #4787

Description of the Change

I hope this will be the last in this series of PRs. This change fixes some edge cases during server start and client connect that can still leave the app in a bad state.

For server starts, some extra care is taken in the order of operations. We now always create the server first (if any) and then create the local client. And we always start the server first then start the local client. If the server fails to start with an IOException, we can just propagate the exception since the caller handles that case. If the client fails to start, we make a point of stopping the already-started server before propagating the exception.

The previous point also required some internal changes to servers and clients. Any IOException thrown in their start() methods will result in their states being set to Stopped and Closed respectively. This avoids the possibility that such a client or server is mistakenly identified as still running.

On the handshake side, the completion callbacks now receive a flag indicating whether the handshake was a success. Some of these callbacks have behaviour that should only trigger in success cases, while others have logic for both cases. An important case is that glass panes are hidden regardless of outcome, but a new glass pane is only installed if proceeding to the next step. MapToolClient now treats handshake failures as an unexpected disconnection.

Possible Drawbacks

Should be none.

Documentation Notes

N/A

Release Notes

  • Fixed a bug where some server start failures and some early connection failures could leave MapTool unusable.

This change is Reviewable

For both `MapToolClient.start()`, if an `IOException` is thrown we now guarantee that the state will be `Closed`. This
means the caller doesn't have to worry about cleaning up the client by calling `.close()` themselves on an object with
some indeterminate state. Similar thing for `MapToolServer.start()` - its state will be set to `Stopped` if an
`IOException` is thrown.

`MapTool.startServer()` now relies on this by catching any `IOException` from the client. In this case it stops the
server before propagating the exception. This makes sure both client and server are in a determinate state if
`startServer()` fails.

The change to `SocketServer.start()` is only to make it more clear what the state will be in case of a failure.
onComplete callbacks ow receive a flag indicating whether the handshake was successful. This allows us to bail early and
to avoid proceeding with logic that assumes a successful connection. On the disconnect side, some logic was moved around
to where it makes more sense, in particular expected disconnects resulting from `AppActions.DISCONNECT_FROM_SERVER`.

Clients are now created after their respective servers if any. This isn't a huge deal, but is more intuitive and allows
us a bit of an easier time in the client disconnect handler.
The parameters were never been filled because the server does not produce its version in the handshake message. This
could be fixed, but comes with BC concerns so I just fixed the strings for now.
@cwisniew cwisniew added this pull request to the merge queue May 23, 2024
Merged via the queue into RPTools:develop with commit bf7fd9f May 23, 2024
5 checks passed
@kwvanderlinde kwvanderlinde deleted the bugfix/4787-error-handling-for-server-and-client-starts branch May 23, 2024 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

2 participants