fix: cancel ALSA receive subscription on disconnect for clean shutdown#13
Open
thorinside wants to merge 1 commit intoInvisibleWrench:masterfrom
Open
fix: cancel ALSA receive subscription on disconnect for clean shutdown#13thorinside wants to merge 1 commit intoInvisibleWrench:masterfrom
thorinside wants to merge 1 commit intoInvisibleWrench:masterfrom
Conversation
…utdown - Store StreamSubscription from _device.receivedMessages.listen() - Cancel subscription in disconnect() before closing ALSA device - Close both _setupStreamController and _rxStreamController in teardown() - Use .toList() to avoid concurrent modification during teardown Fixes app hang on Linux shutdown caused by uncancelled ALSA receive loop
Contributor
|
Thanks for this fix @thorinside 👍🏻 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Linux, disconnecting a MIDI device (or shutting down the app) can hang indefinitely. The root cause is that the
StreamSubscriptionfrom_device.receivedMessages.listen()is never cancelled before the ALSA device is closed, leaving an active read loop blocking the isolate.Additionally,
_setupStreamControllerand_rxStreamControllerare not closed during teardown, and iterating_connectedDeviceswhile modifying it during teardown causes aConcurrentModificationError.Fix
StreamSubscriptionreturned byreceivedMessages.listen()disconnect()before closing the ALSA device_setupStreamControllerand_rxStreamControllerduring teardown.toList()when iterating_connectedDevicesduring teardown to avoid concurrent modificationRelated
The underlying
dart_midipackage also has an ALSA shutdown hang that is fixed separately: maks/dart_midi#8. That PR closes the ALSA port before killing the receive isolate, which complements this fix at theflutter_midi_command_linuxlevel.Testing
Verified on Linux with:
Developed and tested as part of nt_helper.