Skip to content

Conversation

@graebm
Copy link
Contributor

@graebm graebm commented May 14, 2019

TLDR; Implemented aws_websocket_close(). Also added return values to many callbacks, which allow the user to stop read/write processing by returning false.

Details:
This is different than HTTP, where callbacks don't have return values, but a call to _close() from within a callback is guaranteed to stop read/write processing. It was too complex trying to get this working in websockets, whose shutdown procedure is more complex. Therefore I did the simple and direct thing. If a user realizes in a callback that something has gone wrong and processing cannot succeed, they return false.

I'll do a consistency pass eventually on the HTTP layer once websockets is done, making it work like this as well.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@graebm graebm requested a review from a team May 14, 2019 20:03
@graebm graebm merged commit 9e8fbce into master May 14, 2019
@graebm graebm deleted the defenestrate branch May 14, 2019 21:52
graebm added a commit that referenced this pull request Aug 16, 2024
The bug was introduced in [PR #474](https://github.com/awslabs/aws-c-http/pull/474/files#diff-ee776c7576cfff50a64158d59a6173ab9a0aa373150574aa9987b4f8726b58e3)
  - `is_writing_stopped = true` shouldn't be set directly, there's a helper function `s_stop_writing()` that ensures subsequent calls to `aws_websocket_send_frame()` will fail.

Let's take a whole new approach these channel-shutdown-window-deadlock issues:
- add `s_stop_reading_and_dont_block_shutdown()` function that sets `is_reading_stopped = true`, but also increments the read window so that channel shutdown won't deadlock.
    - Most places that were setting `is_reading_stopped = true` now use this helper instead
- Revamp how `aws_channel_shutdown()` is called. Lots of channel behavior has changed since [this websocket code was written](#48).
  - If on the channel-thread, just call `aws_channel_shutdown()`
      - now that [aws_channel_shutdown()](awslabs/aws-c-io#172) is always async, we don't need to defensively schedule a task to call it
  - If off-thread, use `s_schedule_channel_shutdown_from_offthead()`
      - now that this is only called from `aws_websocket_close()`, or when the refcount goes to zero, we can assume the user is OK if reading stops, and it can call `s_stop_reading_and_dont_block_shutdown()` on the way to shutting down.
- Add the test to verify that send after close should fail

Co-authored-by: Michael Graeb <graebm@amazon.com>
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.

2 participants