Skip to content

(hopefully) fix send on closed channel panic #621

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

Merged
merged 1 commit into from
Mar 2, 2021
Merged

Conversation

umbynos
Copy link
Contributor

@umbynos umbynos commented Feb 24, 2021

Please check if the PR fulfills these requirements

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • Tests for the changes have been added (for bug fixes / features)
  • What kind of change does this PR introduce?

bug fix

  • What is the current behavior?

Sometimes the agent crashes with this panic when closing the serial panel on create:

panic: send on closed channel

goroutine 52 [running]:
main.(*BufferflowTimed).Close(0xc00014ee80)
	/Users/runner/work/arduino-create-agent/arduino-create-agent/bufferflow_timed.go:114 +0x53
main.spCloseReal(0xc000079020)
	/Users/runner/work/arduino-create-agent/arduino-create-agent/serialport.go:364 +0x34
main.spHandlerClose(...)
	/Users/runner/work/arduino-create-agent/arduino-create-agent/serialport.go:360
main.spClose(0xc00027c826, 0x15)
	/Users/runner/work/arduino-create-agent/arduino-create-agent/serial.go:241 +0x117
created by main.checkCmd
	/Users/runner/work/arduino-create-agent/arduino-create-agent/hub.go:142 +0x7fd

  • What is the new behavior?

The problem comes from the fact that Close function in bufferflow_timed.go could be called when b.done is already closed.
Moving the close in the sender should solve the issue. Apparently is always possible to read from a closed channel, but writing causes a panic

  • Does this PR introduce a breaking change?

no

  • Other information:

@umbynos umbynos self-assigned this Feb 24, 2021
@umbynos umbynos requested a review from zmoog February 24, 2021 15:32
@umbynos umbynos force-pushed the umbynos/fix_channel branch from 8ff92a3 to ef1a696 Compare February 24, 2021 16:21
@umbynos umbynos requested review from rsora and removed request for zmoog February 25, 2021 11:37
@umbynos umbynos force-pushed the umbynos/fix_channel branch from ef1a696 to eb32a1e Compare March 2, 2021 09:56
Copy link
Contributor

@rsora rsora left a comment

Choose a reason for hiding this comment

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

👍

@umbynos umbynos merged commit 249cc81 into devel Mar 2, 2021
@umbynos umbynos deleted the umbynos/fix_channel branch March 2, 2021 10:03
umbynos added a commit that referenced this pull request Aug 4, 2021
umbynos added a commit that referenced this pull request Aug 18, 2021
* update bufferflow_timedraw as bufferflow_timed

* remove old commands

* remove utf8 decoding with timedraw buffer type

* binary support (WIP)

* use switch case

* fixed test deps

* socketio test connection is working 🎉 (with the correct python-socketio version)

* add callback to capture returned message, add new test for serial

* fix tests: "socketio.exceptions.ConnectionError: Connection refused by the server"

* minor optimizations: data and buf are already an array of bytes

* enhanced a bit how the logic of the serial works

* enhance a lot test on serial communication (with different buffer types)

The tests should be skipped on the CI (no board connected)

* update and enhance commands output (the space in front of `<` and `>` is required) 🤷‍♂️

* increased sleeptime, remove harcoded message[i]: should work on different systems

* generalize the tests

* Apply suggestions from code review

Co-authored-by: per1234 <[email protected]>

* add sketch used for testing

* Fix panic closing closed channel

* apply suggestions

* Partially revert #e80400b7ddbbc2e8f34f1e6701b55102c3a99289

* 🧹(cleanup) and 🛠️(refactoring) of bufferflow stuff

* extract code in helper function and uniform the code

reintroduce the closing of input channel (it's required)

* optimize the handling of data coming from the serial port

* uniform default bufferflow and 🧹

* forgot to fix this in #621

* apply suggestions from code review ✨

* remove timedbinary: it's the same as timedraw except for the casting

* Escape html commands string

* forgot to remove timed_binary

* remove useless id field (was unused)

* remove useless channel done & other stuff

* make sendNoBuf more general: will be used later 😏

* add `sendraw` command to send base64 encoded bytes, add tests (for send raw and for open/close port)

* forgot to skip test_sendraw_serial on CI

* update comments

* refactor tests

* remove BlockUntilReady because it was unused

Co-authored-by: per1234 <[email protected]>
Co-authored-by: Silvano Cerza <[email protected]>
umbynos added a commit that referenced this pull request Aug 18, 2021
* update bufferflow_timedraw as bufferflow_timed

* remove old commands

* remove utf8 decoding with timedraw buffer type

* binary support (WIP)

* use switch case

* fixed test deps

* socketio test connection is working 🎉 (with the correct python-socketio version)

* add callback to capture returned message, add new test for serial

* fix tests: "socketio.exceptions.ConnectionError: Connection refused by the server"

* minor optimizations: data and buf are already an array of bytes

* enhanced a bit how the logic of the serial works

* enhance a lot test on serial communication (with different buffer types)

The tests should be skipped on the CI (no board connected)

* update and enhance commands output (the space in front of `<` and `>` is required) 🤷‍♂️

* increased sleeptime, remove harcoded message[i]: should work on different systems

* generalize the tests

* Apply suggestions from code review

Co-authored-by: per1234 <[email protected]>

* add sketch used for testing

* Fix panic closing closed channel

* apply suggestions

* Partially revert #e80400b7ddbbc2e8f34f1e6701b55102c3a99289

* 🧹(cleanup) and 🛠️(refactoring) of bufferflow stuff

* extract code in helper function and uniform the code

reintroduce the closing of input channel (it's required)

* optimize the handling of data coming from the serial port

* uniform default bufferflow and 🧹

* forgot to fix this in #621

* apply suggestions from code review ✨

* remove timedbinary: it's the same as timedraw except for the casting

* Escape html commands string

* forgot to remove timed_binary

* remove useless id field (was unused)

* remove useless channel done & other stuff

* make sendNoBuf more general: will be used later 😏

* add `sendraw` command to send base64 encoded bytes, add tests (for send raw and for open/close port)

* forgot to skip test_sendraw_serial on CI

* update comments

* refactor tests

* remove BlockUntilReady because it was unused

Co-authored-by: per1234 <[email protected]>
Co-authored-by: Silvano Cerza <[email protected]>
@rsora rsora added the type: imperfection Perceived defect in any part of project label Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants