elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.63k stars 300 forks source link

panic with values from background job #1398

Open hanche opened 2 years ago

hanche commented 2 years ago

The shell panics when a background job tries to send on the values channel:

⬥ { sleep 1; put boom } &
⬥ panic: send on closed channel

goroutine 2875 [running]:
src.elv.sh/pkg/eval.valueOutput.Put(0xc00050d080, 0x0, 0x0, 0x4443880, 0xc000295000, 0x4454901, 0x0)
    src.elv.sh/pkg/eval/port.go:280 +0xa5
src.elv.sh/pkg/eval.put(0xc0002da5b0, 0xc00038a550, 0x1, 0x1, 0x0, 0x0)
    src.elv.sh/pkg/eval/builtin_fn_io.go:95 +0xbe
reflect.Value.call(0x44549c0, 0x4509520, 0x13, 0x44e25b7, 0x4, 0xc00036ea50, 0x2, 0x2, 0x2, 0x18, ...)
    reflect/value.go:476 +0x8e7
reflect.Value.Call(0x44549c0, 0x4509520, 0x13, 0xc00036e810, 0x2, 0x2, 0x1, 0x2, 0x43ab3dc)
    reflect/value.go:337 +0xb9
src.elv.sh/pkg/eval.(*goFn).Call(0xc00013f960, 0xc0002da5b0, 0xc00038a520, 0x1, 0x1, 0xc00036e5d0, 0x0, 0x1)
    src.elv.sh/pkg/eval/go_fn.go:227 +0x658
src.elv.sh/pkg/eval.(*formOp).exec(0xc0002474a0, 0xc0002da5b0, 0x0, 0x0)
    src.elv.sh/pkg/eval/compile_effect.go:377 +0x9a2
src.elv.sh/pkg/eval.(*pipelineOp).exec.func1(0x456e9a0, 0xc0002474a0, 0xc0002da5b0, 0x0, 0xc00038a500, 0xc000295000, 0xc0004281b0)
    src.elv.sh/pkg/eval/compile_effect.go:122 +0x3f
created by src.elv.sh/pkg/eval.(*pipelineOp).exec
    src.elv.sh/pkg/eval/compile_effect.go:121 +0x22c
Exception: elvish exited with 2
[tty 3], line 1: elvish

If you run any nontrivial elvish code in the background, this can easily snag you.

krader1961 commented 2 years ago

I reported this bug fifteen months ago in issue #1069. I closed my issue three months ago because it seemed to be fixed. I did not pinpoint the specific change that fixed this bug. I simply verified that I could no longer reproduce this failure when I closed my issue three months ago. However, I can reproduce the bug using my scenario and this one today using an Elvish program built from source as of the time I write this comment.