evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
37.93k stars 1.13k forks source link

Random "all goroutines are asleep - deadlock!" on a build #3635

Open btakita opened 7 months ago

btakita commented 7 months ago

I have not seen this error before & cannot reproduce. The project I ran this on is https://github.com/btakita/briantakita.me-dev

git clone git@github.com:btakita/briantakita.me-dev.git
cd briantakita.me-dev
git submodule init
git submodule update
bun i
app--build

It uses rebuildjs, relysjs, & @rebuildjs/tailwindcss...all of which I wrote. The rebuildjs core is a reactive build, which include throw new Cancel, which cancels the existing build process a reactive memo (using rmemo, another library I wrote) starts a new build. I'm mentioning this because it's not a normal use case & it's possible some undiscovered concurrency issues can arise...as seems to be the case here.

fatal error: all goroutines are asleep - deadlock!

goroutine 1 [chan receive]:
github.com/evanw/esbuild/internal/helpers.(*ThreadSafeWaitGroup).Wait(...)
        github.com/evanw/esbuild/internal/helpers/waitgroup.go:36
main.runService.func2()
        github.com/evanw/esbuild/cmd/esbuild/service.go:114 +0x59
main.runService(0x1)
        github.com/evanw/esbuild/cmd/esbuild/service.go:160 +0x4ed
main.main()
        github.com/evanw/esbuild/cmd/esbuild/main.go:240 +0xa29

goroutine 18 [chan receive]:
main.runService.func1()
        github.com/evanw/esbuild/cmd/esbuild/service.go:98 +0x4a
created by main.runService
        github.com/evanw/esbuild/cmd/esbuild/service.go:97 +0x1e5

goroutine 19 [chan receive]:
main.(*serviceType).sendRequest(0xc000128030, {0x93c500, 0xc001652bd0})
        github.com/evanw/esbuild/cmd/esbuild/service.go:192 +0xfa
main.runService.func3()
        github.com/evanw/esbuild/cmd/esbuild/service.go:125 +0x39
created by main.runService
        github.com/evanw/esbuild/cmd/esbuild/service.go:122 +0x31c
btakita commented 7 months ago

Actually, another build is not started. There is only one call to esbuild_ctx.rebuild() on the production environment. Sorry about the misstatement above. The Cancel logic is contained within various rmemos which:

sync the concurrent browser + server builds → hold state derived from metafile.json → post-build work → modify the state → persist the new state to metafile.json.

The app build logic is in https://github.com/btakita/briantakita.me/blob/main/build.ts, where @btakita/briantakita.me is a submodule in the btakita/briantakita.me-dev project.

From an esbuild perspective, one thing that is unusual is that two concurrent .rebuild() calls occur...for the browser & server...with each build having multiple entry points.

btakita commented 7 months ago

Environment

Linux 6.7.2-arch1-1 x86_64 unknown
bun 1.0.26
XhstormR commented 4 months ago

I have the same issue here when i start the dev angular server.

=> bun start
$ ng serve
Initial chunk files | Names               |   Raw size
styles.css          | styles              |   94.53 kB |
polyfills.js        | polyfills           |   83.60 kB |
main.js             | main                |    6.68 kB |
chunk-UGWGSAMD.js   | -                   |    2.31 kB |
chunk-EANWZMW4.js   | -                   | 1023 bytes |

                    | Initial total       |  188.12 kB

Lazy chunk files    | Names               |   Raw size
chunk-I236AL25.js   | dashboard-component |   33.66 kB |
chunk-CMETQZE2.js   | home-component      |   11.36 kB |
chunk-KVA7RMZL.js   | -                   |    9.16 kB |

Application bundle generation complete. [4.077 seconds]

Watch mode enabled. Watching for file changes...
  ➜  Local:   http://localhost:4200/
  ➜  press h + enter to show help
q
fatal error: all goroutines are asleep - deadlock!

goroutine 1 [chan receive]:
github.com/evanw/esbuild/internal/helpers.(*ThreadSafeWaitGroup).Wait(...)
        github.com/evanw/esbuild/internal/helpers/waitgroup.go:36
main.runService.func2()
        github.com/evanw/esbuild/cmd/esbuild/service.go:114 +0x59
main.runService(0x1)
        github.com/evanw/esbuild/cmd/esbuild/service.go:160 +0x4ed
main.main()
        github.com/evanw/esbuild/cmd/esbuild/main.go:240 +0xa29

goroutine 4 [chan receive]:
main.runService.func1()
        github.com/evanw/esbuild/cmd/esbuild/service.go:98 +0x4a
created by main.runService
        github.com/evanw/esbuild/cmd/esbuild/service.go:97 +0x1e5

goroutine 5 [chan receive]:
main.(*serviceType).sendRequest(0xc00017c090, {0x1540680, 0xc000ad3e00})
        github.com/evanw/esbuild/cmd/esbuild/service.go:192 +0xfa
main.runService.func3()
        github.com/evanw/esbuild/cmd/esbuild/service.go:125 +0x39
created by main.runService
        github.com/evanw/esbuild/cmd/esbuild/service.go:122 +0x31c
MrP commented 4 months ago

I have the same issue on an angular build, @XhstormR, on a Linux Azure Pipeline build. Did you ever find out what's going on?