Skip to content

fix: Allow event listeners to remove themselves inside their handler - #2755

Merged
hampuslavin merged 1 commit into
serverpod:mainfrom
hampuslavin:hl_fix_revoked_auth_stream
Sep 18, 2024
Merged

hampuslavin merged 1 commit into
serverpod:mainfrom
hampuslavin:hl_fix_revoked_auth_stream

Conversation

@hampuslavin

@hampuslavin hampuslavin commented Sep 18, 2024 •

Copy link
Copy Markdown
Contributor

Description

Fixes #2754. The revoked authentication handler removed itself inside its event handler, causing an exception to be thrown:

Concurrent modification during iteration: _Set len:0.
#0      _CompactIterator.moveNext (dart:collection-patch/compact_hash.dart:714:7)
#1      MessageCentral.postMessage (package:serverpod/src/server/message_central.dart:61:28)

This stopped the iteration and prevented all handlers to be called.

💡 Note that this exception was silently failing because the server will not shutdown on exceptions, but it was visible in the server log

Changes

  • Simply adds .toList to the callback list to create a copy. This allows the event handler to remove itself (or indeed add new handlers).
  • Adds test cases which were failing before the fix (by timeout, since the second stream was never closed).

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

@hampuslavin
hampuslavin requested a review from Isakdl September 18, 2024 09:51

@Isakdl Isakdl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hampuslavin
hampuslavin merged commit 656c206 into serverpod:main Sep 18, 2024
@hampuslavin
hampuslavin deleted the hl_fix_revoked_auth_stream branch September 18, 2024 10:03
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Revoked authentication does not work for multiple streams

2 participants