-
Notifications
You must be signed in to change notification settings - Fork 18k
syscall/js: "goroutines are asleep" error only in Node.js #32764
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
Comments
Thinking out loud, but presumably this incompatibility is lurking somewhere in |
This is expected. The following code is only used by Node.js: Lines 525 to 531 in 5f4aa5d
The reasoning is that if all goroutines are asleep AND there is no Node.js event handler pending, then the program can never continue, which is a "deadlock" situation. In fact, the default behavior of Node.js is to just quit with exit code 0, because there is no code to run any more 😒. I opted for throwing the error instead. |
I see. Then does this mean in Node.js, we can never attach a global callback without hooking into the event loop somehow ? |
The issue is not the callback, but that there is no code at all running any more, thus the application would hang forever. Explicitly saying "this is a deadlock" is a feature, not a bug. What are you trying to do? |
I was trying to debug this - #26277. Then realized that the code gives this deadlock error, which obviously did not give at that time. Reduced it to this test case. Hence, I was trying to get to the root of it. Full code here
package main
import ( var headers js.Value func init() { func main() { func request(this js.Value, args []js.Value) interface{} { func listen(this js.Value, args []js.Value) interface{} { func wait() { |
The problem with this code is that you are doing a blocking operation ( If you replace However, the stack of the hanging |
Aha ! Missed that one. Sorry I went down a different rabbit hole. Thanks for looking into it. |
Change https://golang.org/cl/199537 mentions this issue: |
On wasm there is a special goroutine that handles asynchronous events. Blocking this goroutine often causes a deadlock. However, the stack trace of this goroutine was omitted when printing the deadlock error. This change adds an exception so the goroutine is not considered as an internal system goroutine and the stack trace gets printed, which helps with debugging the deadlock. Updates #32764 Change-Id: Icc8f5ba3ca5a485d557b7bdd76bf2f1ffb92eb3e Reviewed-on: https://go-review.googlesource.com/c/go/+/199537 Run-TryBot: Richard Musiol <neelance@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This is resolved. Closing. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
I ran this in both browser and Node.js.
What did you expect to see?
I expect in both cases, for the program to wait indefinitely.
What did you see instead?
In works fine in browser:
But fails in Node.js
Is this expected ?
My node version is 10.2.1
/cc @neelance
I haven't tried with 1.11 because the function semantics have changed since.
The text was updated successfully, but these errors were encountered: