lrstanley / girc

:bomb: girc is a flexible IRC library for Go :ok_hand:
https://pkg.go.dev/github.com/lrstanley/girc
MIT License
137 stars 13 forks source link

fix: race condition (closes #63) #64

Closed Wessie closed 5 months ago

Wessie commented 5 months ago

Logic race condition, if the decode goroutine can run before the caller can, the channel returned might not have a receiver yet and then the select/default construct will drop the event and close the channel.

The caller then ends up with a zero-value decodedEvent where decodedEvent.err and decodedEvent.event are both nil which passes the err check at line 434 and might enter line 440 where decodedEvent.event is then used as-is with no additional check for it being nil.

Fixed this scenario by giving the returned channel a buffer slot so that decode can always send its event.

yunginnanet commented 5 months ago

nailed it

codecov-commenter commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (f477179) 55.99% compared to head (819351e) 56.25%. Report is 3 commits behind head on master.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #64 +/- ## ========================================== + Coverage 55.99% 56.25% +0.26% ========================================== Files 13 13 Lines 3488 3484 -4 ========================================== + Hits 1953 1960 +7 + Misses 1409 1401 -8 + Partials 126 123 -3 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.