Skip to content
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

Crash when creating and reading local variable concurrently #754

Closed
notramo opened this issue Sep 23, 2018 · 4 comments
Closed

Crash when creating and reading local variable concurrently #754

notramo opened this issue Sep 23, 2018 · 4 comments
Labels

Comments

@notramo
Copy link

notramo commented Sep 23, 2018

I added the following to my rc.elv (it uses fzf for directory history matching):

edit:location:matcher = [pattern]{ input = [];
  each [in]{ input = [ $@input $in ] };
  for i $input {
    print $i"\x00"
  }|
    output = [(fzf --read0 -f $pattern)];
  for i $input {
    has-value $output $i
  }
}

Crash happens randomly. Probably when multiple fzf instances are running (I have a slow CPU).
OS: Void Linux glibc, but it also happens on Arch Linux (both x86_64).
Version (on Void):

Version: 0.12-rc2-dirty
Go version: go1.10.3
GOROOT at build time: /usr/lib/go
GOPATH at build time: /home/user/.go/

Backtrace:

 ~ >>>                                                                                                                                                                    [ user ]
 LOCATION  ffffffatal error: concurrent map read and map write
(no result)
goroutine 44095 [running]:
runtime.throw(0x91f468, 0x21)
/usr/lib/go/src/runtime/panic.go:616 +0x81 fp=0xc4202fb990 sp=0xc4202fb970 pc=0x42b9c1
runtime.mapaccess2_faststr(0x8efb00, 0xc4205a8690, 0xc420250029, 0x1, 0xc4202fba70, 0x0)
/usr/lib/go/src/runtime/hashmap_fast.go:270 +0x461 fp=0xc4202fba00 sp=0xc4202fb990 pc=0x40cc41
github.com/elves/elvish/eval.(*Frame).resolveUnqualified(...)
/home/user/.go/src/github.com/elves/elvish/eval/resolve.go:139
github.com/elves/elvish/eval.(*Frame).ResolveVar(0xc42027ff20, 0xc420250029, 0x0, 0xc420250029, 0x1, 0x300000002, 0xc4201abb00)
/home/user/.go/src/github.com/elves/elvish/eval/resolve.go:80 +0x6e6 fp=0xc4202fbad8 sp=0xc4202fba00 pc=0x7a41d6
github.com/elves/elvish/eval.varOp.Invoke(0xc420250029, 0x0, 0xc420250029, 0x1, 0xc42027ff20, 0x4854d0, 0xc42017c7d0, 0x7abdca, 0xc4201e33c0, 0x412938)
/home/user/.go/src/github.com/elves/elvish/eval/compile_lvalue.go:144 +0x63 fp=0xc4202fbb50 sp=0xc4202fbad8 pc=0x78e493
github.com/elves/elvish/eval.(*varOp).Invoke(0xc420369a40, 0xc42027ff20, 0xc4201e34a8, 0x797b54, 0x855840, 0xc420580000, 0x1000)
<autogenerated>:1 +0x69 fp=0xc4202fbbb0 sp=0xc4202fbb50 pc=0x7b1a79
github.com/elves/elvish/eval.LValuesOp.Exec(0x971440, 0xc420369a40, 0x829, 0x82a, 0xc42027ff20, 0xc420580000, 0x1000, 0x1000, 0x7a5513, 0x971460)
/home/user/.go/src/github.com/elves/elvish/eval/compile_lvalue.go:30 +0x56 fp=0xc4202fbbf8 sp=0xc4202fbbb0 pc=0x78d626
github.com/elves/elvish/eval.(*forOp).Invoke(0xc42035bf00, 0xc42027ff20, 0xc4201e3500, 0x4ea1ac)
/home/user/.go/src/github.com/elves/elvish/eval/builtin_special.go:505 +0x6b fp=0xc4202fbcb8 sp=0xc4202fbbf8 pc=0x78a79b
github.com/elves/elvish/eval.(*formOp).Invoke(0xc420371790, 0xc42027ff20, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:322 +0xe00 fp=0xc4202fbe90 sp=0xc4202fbcb8 pc=0x7915d0
github.com/elves/elvish/eval.Op.Exec(0x9704a0, 0xc420371790, 0x825, 0x84a, 0xc42027ff20, 0x1000, 0x1000)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:30 +0x4d fp=0xc4202fbec0 sp=0xc4202fbe90 pc=0x78ee6d
github.com/elves/elvish/eval.(*Frame).Eval(0xc42027ff20, 0x9704a0, 0xc420371790, 0x825, 0x84a, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/eval/frame.go:129 +0xa2 fp=0xc4202fbf30 sp=0xc4202fbec0 pc=0x79e2b2
github.com/elves/elvish/eval.(*pipelineOp).Invoke.func1(0xc42027ff20, 0x9704a0, 0xc420371790, 0x825, 0x84a, 0xc42018d2b0, 0xc42023cf10, 0x0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:118 +0x60 fp=0xc4202fbfa0 sp=0xc4202fbf30 pc=0x7a8380
runtime.goexit()
/usr/lib/go/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc4202fbfa8 sp=0xc4202fbfa0 pc=0x4593c1
created by github.com/elves/elvish/eval.(*pipelineOp).Invoke
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:117 +0x18d

goroutine 1 [semacquire]:
sync.runtime_Semacquire(0xc42023cf1c)
/usr/lib/go/src/runtime/sema.go:56 +0x39
sync.(*WaitGroup).Wait(0xc42023cf10)
/usr/lib/go/src/sync/waitgroup.go:129 +0x72
github.com/elves/elvish/eval.(*pipelineOp).Invoke(0xc420242ff0, 0xc4202f26c0, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:155 +0x566
github.com/elves/elvish/eval.Op.Exec(0x970540, 0xc420242ff0, 0x825, 0x874, 0xc4202f26c0, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:30 +0x4d
github.com/elves/elvish/eval.chunkOp.Invoke(0xc42035be80, 0x4, 0x4, 0xc4202f26c0, 0x1500000000000030, 0x8ecca0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:43 +0x81
github.com/elves/elvish/eval.Op.Exec(0x971240, 0xc4203843c0, 0x7ee, 0x8a4, 0xc4202f26c0, 0xc42031a020, 0xc42005ea08)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:30 +0x4d
github.com/elves/elvish/eval.(*Closure).Call(0xc42045bf40, 0xc4202f26c0, 0xc42044e110, 0x1, 0x1, 0xc4201701e0, 0x4120e9, 0xc4201a6420)
/home/user/.go/src/github.com/elves/elvish/eval/closure.go:130 +0x864
github.com/elves/elvish/eval.(*Frame).CaptureOutput.func1(0xc4202f26c0, 0x18, 0x1000000008c42c0)
/home/user/.go/src/github.com/elves/elvish/eval/frame.go:159 +0x5d
github.com/elves/elvish/eval.funcOp.Invoke(0xc420414280, 0xc4202f26c0, 0x10, 0xc42005ed28)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:574 +0x30
github.com/elves/elvish/eval.Op.Exec(0x971320, 0xc420414280, 0xffffffffffffffff, 0xffffffffffffffff, 0xc4202f26c0, 0x434e24, 0xc42005ed58)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:30 +0x4d
github.com/elves/elvish/eval.(*Frame).Eval(0xc4202f26c0, 0x971320, 0xc420414280, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/eval/frame.go:129 +0xa2
github.com/elves/elvish/eval.pcaptureOutputInner(0xc42005f038, 0x971320, 0xc420414280, 0xffffffffffffffff, 0xffffffffffffffff, 0xc420340660, 0xc420340680, 0x412938, 0x40)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:373 +0x29b
github.com/elves/elvish/eval.pcaptureOutput(0xc42005f038, 0x971320, 0xc420414280, 0xffffffffffffffff, 0xffffffffffffffff, 0x4100aa, 0x10, 0x8512e0, 0x8ecc01, 0xc42044e120)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:342 +0x168
github.com/elves/elvish/eval.(*Frame).CaptureOutput(0xc42005f038, 0x7f8269cf30a0, 0xc42045bf40, 0xc42044e110, 0x1, 0x1, 0xc4201701e0, 0x0, 0x6, 0xc42060fe10, ...)
/home/user/.go/src/github.com/elves/elvish/eval/frame.go:161 +0xd8
github.com/elves/elvish/edit/location.(*provider).Filter(0xc4202f23c0, 0xc42060fe10, 0x6, 0x0)
/home/user/.go/src/github.com/elves/elvish/edit/location/location.go:280 +0x433
github.com/elves/elvish/edit/edcore.(*listingState).refresh(0xc42007a190)
/home/user/.go/src/github.com/elves/elvish/edit/edcore/listing.go:263 +0x46
github.com/elves/elvish/edit/edcore.(*listingState).changeFilter(0xc42007a190, 0xc42060fe10, 0x6)
/home/user/.go/src/github.com/elves/elvish/edit/edcore/listing.go:259 +0x4b
github.com/elves/elvish/edit/edcore.(*listingState).defaultBinding(0xc42007a190, 0xc4201c2000)
/home/user/.go/src/github.com/elves/elvish/edit/edcore/listing.go:337 +0xd8
github.com/elves/elvish/edit/edcore.initListing.func10()
/home/user/.go/src/github.com/elves/elvish/edit/edcore/listing.go:54 +0x39
reflect.Value.call(0x84a320, 0xc42015e560, 0x13, 0x90d134, 0x4, 0x0, 0x0, 0x0, 0x1d, 0x84a320, ...)
/usr/lib/go/src/reflect/value.go:447 +0x969
reflect.Value.Call(0x84a320, 0xc42015e560, 0x13, 0x0, 0x0, 0x0, 0x7b8d8d, 0xc42000e020, 0xc4204722c0)
/usr/lib/go/src/reflect/value.go:308 +0xa4
github.com/elves/elvish/eval.(*BuiltinFn).Call(0xc42015af00, 0xc4202f2600, 0x0, 0x0, 0x0, 0xc4201701e0, 0x8ecca0, 0xc42005f6f8)
/home/user/.go/src/github.com/elves/elvish/eval/builtin_fn.go:184 +0x55c
github.com/elves/elvish/eval.(*Frame).Call(0xc4202f2600, 0x970380, 0xc42015af00, 0x0, 0x0, 0x0, 0xc4201701e0, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/eval/frame.go:143 +0xbb
github.com/elves/elvish/edit/edcore.(*editor).CallFn(0xc4201c2000, 0x970380, 0xc42015af00, 0x0, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/edit/edcore/api.go:115 +0x257
github.com/elves/elvish/edit/edcore.(*editor).ReadLine(0xc4201c2000, 0x0, 0x0, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/edit/edcore/edit.go:496 +0x9e0
github.com/elves/elvish/program/shell.interact.func1(0x895c00, 0xc42031fbc0, 0x13, 0x0)
/home/user/.go/src/github.com/elves/elvish/program/shell/interact.go:41 +0x2f
github.com/elves/elvish/program/shell.interact(0xc4200c70e0, 0xc4200223c0, 0x13, 0x0)
/home/user/.go/src/github.com/elves/elvish/program/shell/interact.go:51 +0x219
github.com/elves/elvish/program/shell.(*Shell).Main(0xc42018e440, 0xc42001e1a0, 0x0, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/program/shell/shell.go:48 +0x1a7
github.com/elves/elvish/program.Main(0xc42001e1a0, 0x1, 0x1, 0x0)
/home/user/.go/src/github.com/elves/elvish/program/program.go:119 +0x180
main.main()
/home/user/.go/src/github.com/elves/elvish/main.go:14 +0x45

goroutine 5 [syscall]:
os/signal.signal_recv(0x973ee0)
/usr/lib/go/src/runtime/sigqueue.go:139 +0xa6
os/signal.loop()
/usr/lib/go/src/os/signal/signal_unix.go:22 +0x22
created by os/signal.init.0
/usr/lib/go/src/os/signal/signal_unix.go:28 +0x41

goroutine 7 [chan receive]:
github.com/elves/elvish/eval.init.13.func1()
/home/user/.go/src/github.com/elves/elvish/eval/port.go:49 +0x53
created by github.com/elves/elvish/eval.init.13
/home/user/.go/src/github.com/elves/elvish/eval/port.go:48 +0x49

goroutine 8 [IO wait]:
internal/poll.runtime_pollWait(0x7f8269ceef00, 0x72, 0xc420063ab8)
/usr/lib/go/src/runtime/netpoll.go:173 +0x57
internal/poll.(*pollDesc).wait(0xc42016e218, 0x72, 0xffffffffffffff00, 0x971c20, 0xb8d6e8)
/usr/lib/go/src/internal/poll/fd_poll_runtime.go:85 +0x9b
internal/poll.(*pollDesc).waitRead(0xc42016e218, 0xc420193000, 0x1000, 0x1000)
/usr/lib/go/src/internal/poll/fd_poll_runtime.go:90 +0x3d
internal/poll.(*FD).Read(0xc42016e200, 0xc420193000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/lib/go/src/internal/poll/fd_unix.go:157 +0x17d
net.(*netFD).Read(0xc42016e200, 0xc420193000, 0x1000, 0x1000, 0xc4205661a0, 0x197, 0xc420566e80)
/usr/lib/go/src/net/fd_unix.go:202 +0x4f
net.(*conn).Read(0xc42000e598, 0xc420193000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/lib/go/src/net/net.go:176 +0x6a
bufio.(*Reader).Read(0xc420094240, 0xc420025071, 0x1, 0x9, 0xc420063c98, 0x10, 0xc420001e00)
/usr/lib/go/src/bufio/bufio.go:216 +0x238
io.ReadAtLeast(0x96ffe0, 0xc420094240, 0xc420025071, 0x1, 0x9, 0x1, 0xc420063d10, 0x42add4, 0x9351e8)
/usr/lib/go/src/io/io.go:309 +0x86
io.ReadFull(0x96ffe0, 0xc420094240, 0xc420025071, 0x1, 0x9, 0xc420063d48, 0x405ac5, 0x42d79b)
/usr/lib/go/src/io/io.go:327 +0x58
encoding/gob.decodeUintReader(0x96ffe0, 0xc420094240, 0xc420025071, 0x9, 0x9, 0xc42007a020, 0xc420063e08, 0xc420063db8, 0x42a4d9)
/usr/lib/go/src/encoding/gob/decode.go:120 +0x63
encoding/gob.(*Decoder).recvMessage(0xc42016e400, 0xc420063dd0)
/usr/lib/go/src/encoding/gob/decoder.go:80 +0x57
encoding/gob.(*Decoder).decodeTypeSequence(0xc42016e400, 0x936800, 0xc42016e400)
/usr/lib/go/src/encoding/gob/decoder.go:142 +0x136
encoding/gob.(*Decoder).DecodeValue(0xc42016e400, 0x83f2e0, 0xc4201523f0, 0x16, 0x0, 0x0)
/usr/lib/go/src/encoding/gob/decoder.go:210 +0xdc
encoding/gob.(*Decoder).Decode(0xc42016e400, 0x83f2e0, 0xc4201523f0, 0x0, 0x0)
/usr/lib/go/src/encoding/gob/decoder.go:187 +0x14f
net/rpc.(*gobClientCodec).ReadResponseHeader(0xc420170900, 0xc4201523f0, 0xc4205661a0, 0x0)
/usr/lib/go/src/net/rpc/client.go:223 +0x45
net/rpc.(*Client).input(0xc420094300)
/usr/lib/go/src/net/rpc/client.go:109 +0xa7
created by net/rpc.NewClientWithCodec
/usr/lib/go/src/net/rpc/client.go:201 +0x92

goroutine 18 [select, locked to thread]:
runtime.gopark(0x936768, 0x0, 0x90f0f0, 0x6, 0x18, 0x1)
/usr/lib/go/src/runtime/proc.go:291 +0x11a
runtime.selectgo(0xc420042f50, 0xc4201a60c0)
/usr/lib/go/src/runtime/select.go:392 +0xe50
runtime.ensureSigM.func1()
/usr/lib/go/src/runtime/signal_unix.go:549 +0x1f4
runtime.goexit()
/usr/lib/go/src/runtime/asm_amd64.s:2361 +0x1

goroutine 19 [chan receive]:
github.com/elves/elvish/program/shell.handleSignals.func1(0xc4201a6000)
/home/user/.go/src/github.com/elves/elvish/program/shell/shell.go:70 +0xb8
created by github.com/elves/elvish/program/shell.handleSignals
/home/user/.go/src/github.com/elves/elvish/program/shell/shell.go:69 +0x7c

goroutine 20 [IO wait]:
internal/poll.runtime_pollWait(0x7f8269ceec90, 0x72, 0xc420053bc0)
/usr/lib/go/src/runtime/netpoll.go:173 +0x57
internal/poll.(*pollDesc).wait(0xc42015a338, 0x72, 0xffffffffffffff01, 0x971c20, 0xb8d6e8)
/usr/lib/go/src/internal/poll/fd_poll_runtime.go:85 +0x9b
internal/poll.(*pollDesc).waitRead(0xc42015a338, 0xc4201d2001, 0x1000, 0x1000)
/usr/lib/go/src/internal/poll/fd_poll_runtime.go:90 +0x3d
internal/poll.(*FD).Read(0xc42015a320, 0xc4201d2000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/lib/go/src/internal/poll/fd_unix.go:157 +0x17d
os.(*File).read(0xc42015c168, 0xc4201d2000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/lib/go/src/os/file_unix.go:226 +0x4e
os.(*File).Read(0xc42015c168, 0xc4201d2000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/lib/go/src/os/file.go:107 +0x6a
bufio.(*Reader).fill(0xc420053f60)
/usr/lib/go/src/bufio/bufio.go:100 +0x11e
bufio.(*Reader).ReadSlice(0xc420053f60, 0x411c0a, 0x7f8269cf0498, 0x0, 0x0, 0x0, 0x57)
/usr/lib/go/src/bufio/bufio.go:341 +0x2c
bufio.(*Reader).ReadBytes(0xc420053f60, 0xa, 0x0, 0xc42003ce88, 0x442707, 0x1000, 0x8515a0)
/usr/lib/go/src/bufio/bufio.go:419 +0x6b
bufio.(*Reader).ReadString(0xc42003cf60, 0x100a, 0x1000, 0xc4201d2000, 0x1000, 0x1000)
/usr/lib/go/src/bufio/bufio.go:459 +0x38
github.com/elves/elvish/edit/edcore.NewEditor.func1(0xc42015c168, 0xc4201c2000, 0xc420156360)
/home/user/.go/src/github.com/elves/elvish/edit/edcore/edit.go:120 +0x1cc
created by github.com/elves/elvish/edit/edcore.NewEditor
/home/user/.go/src/github.com/elves/elvish/edit/edcore/edit.go:117 +0x2bb

goroutine 21 [chan receive]:
github.com/elves/elvish/edit/edcore.NewEditor.func2(0xc4201a6300, 0xc4201c2000)
/home/user/.go/src/github.com/elves/elvish/edit/edcore/edit.go:132 +0xfe
created by github.com/elves/elvish/edit/edcore.NewEditor
/home/user/.go/src/github.com/elves/elvish/edit/edcore/edit.go:131 +0x2ea

goroutine 9 [chan receive]:
github.com/elves/elvish/edit/prompt.(*prompt).loop(0xc42016e480)
/home/user/.go/src/github.com/elves/elvish/edit/prompt/prompt.go:76 +0xd1
created by github.com/elves/elvish/edit/prompt.makePrompt
/home/user/.go/src/github.com/elves/elvish/edit/prompt/prompt.go:69 +0x1b4

goroutine 10 [chan receive]:
github.com/elves/elvish/edit/prompt.(*prompt).loop(0xc42016e500)
/home/user/.go/src/github.com/elves/elvish/edit/prompt/prompt.go:76 +0xd1
created by github.com/elves/elvish/edit/prompt.makePrompt
/home/user/.go/src/github.com/elves/elvish/edit/prompt/prompt.go:69 +0x1b4

goroutine 931 [runnable]:
syscall.Syscall6(0x10e, 0x7, 0xc42008a300, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0)
/usr/lib/go/src/syscall/asm_linux_amd64.s:44 +0x5
github.com/elves/elvish/vendor/golang.org/x/sys/unix.Pselect(0x7, 0xc42008a300, 0x0, 0x0, 0x0, 0x0, 0xc42015a280, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go:1039 +0xc2
github.com/elves/elvish/sys.Select(0x7, 0xc42008a300, 0x0, 0x0, 0xc4201e06a7, 0x1)
/home/user/.go/src/github.com/elves/elvish/sys/select_linux.go:11 +0x51
github.com/elves/elvish/sys.WaitForRead(0xc4201e06e8, 0x2, 0x2, 0x0, 0x1, 0x0, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/sys/waitforread_unix.go:23 +0x104
github.com/elves/elvish/edit/tty.(*runeReader).run(0xc420158480)
/home/user/.go/src/github.com/elves/elvish/edit/tty/rune_reader_unix.go:67 +0x84
created by github.com/elves/elvish/edit/tty.(*runeReader).Start
/home/user/.go/src/github.com/elves/elvish/edit/tty/rune_reader_unix.go:58 +0x3f

goroutine 932 [select]:
github.com/elves/elvish/edit/tty.(*reader).send(0xc420152750, 0x971120, 0xc42060fe78)
/home/user/.go/src/github.com/elves/elvish/edit/tty/reader_unix.go:100 +0xed
github.com/elves/elvish/edit/tty.(*reader).run(0xc420152750)
/home/user/.go/src/github.com/elves/elvish/edit/tty/reader_unix.go:72 +0x35f
created by github.com/elves/elvish/edit/tty.(*reader).Start
/home/user/.go/src/github.com/elves/elvish/edit/tty/reader_unix.go:58 +0xbb

goroutine 44011 [chan receive]:
github.com/elves/elvish/eval.pcaptureOutput.func1(0xc4202f2720)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:317 +0x66
github.com/elves/elvish/eval.pcaptureOutputInner.func1(0xc420340660, 0xc4202f2720, 0xc4201a6420)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:364 +0x30
created by github.com/elves/elvish/eval.pcaptureOutputInner
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:363 +0x220

goroutine 44012 [IO wait]:
internal/poll.runtime_pollWait(0x7f8269cee6e0, 0x72, 0xc420584b50)
/usr/lib/go/src/runtime/netpoll.go:173 +0x57
internal/poll.(*pollDesc).wait(0xc420204568, 0x72, 0xffffffffffffff01, 0x971c20, 0xb8d6e8)
/usr/lib/go/src/internal/poll/fd_poll_runtime.go:85 +0x9b
internal/poll.(*pollDesc).waitRead(0xc420204568, 0xc42068a001, 0x1000, 0x1000)
/usr/lib/go/src/internal/poll/fd_poll_runtime.go:90 +0x3d
internal/poll.(*FD).Read(0xc420204550, 0xc42068a000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/lib/go/src/internal/poll/fd_unix.go:157 +0x17d
os.(*File).read(0xc4204b20c0, 0xc42068a000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/lib/go/src/os/file_unix.go:226 +0x4e
os.(*File).Read(0xc4204b20c0, 0xc42068a000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/lib/go/src/os/file.go:107 +0x6a
bufio.(*Reader).fill(0xc420584f38)
/usr/lib/go/src/bufio/bufio.go:100 +0x11e
bufio.(*Reader).ReadSlice(0xc420584f38, 0x411c0a, 0x7f8269d01fe8, 0x0, 0x0, 0x0, 0x57)
/usr/lib/go/src/bufio/bufio.go:341 +0x2c
bufio.(*Reader).ReadBytes(0xc420584f38, 0xa, 0x0, 0xc420719e18, 0x442707, 0x1000, 0x8515a0)
/usr/lib/go/src/bufio/bufio.go:419 +0x6b
bufio.(*Reader).ReadString(0xc420719f38, 0x100a, 0x1000, 0xc42068a000, 0x1000, 0x1000)
/usr/lib/go/src/bufio/bufio.go:459 +0x38
github.com/elves/elvish/eval.pcaptureOutput.func2(0xc4204b20c0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:326 +0x16c
github.com/elves/elvish/eval.pcaptureOutputInner.func2(0xc420340680, 0xc4204b20c0, 0xc4201a63c0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:368 +0x30
created by github.com/elves/elvish/eval.pcaptureOutputInner
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:367 +0x259

goroutine 44096 [runnable]:
github.com/elves/elvish/eval.(*Port).Fork(...)
/home/user/.go/src/github.com/elves/elvish/eval/port.go:17
github.com/elves/elvish/eval.(*Frame).fork(0xc42028e000, 0x915565, 0x10, 0xc420044800)
/home/user/.go/src/github.com/elves/elvish/eval/frame.go:115 +0xc3
github.com/elves/elvish/eval.pcaptureOutputInner(0xc42028e000, 0x971240, 0xc420369fa0, 0x85b, 0x872, 0xc420189060, 0xc420189080, 0xc4200652a0, 0x7b0038)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:348 +0x55
github.com/elves/elvish/eval.pcaptureOutput(0xc42028e000, 0x971240, 0xc420369fa0, 0x85b, 0x872, 0x0, 0x0, 0xc4200655b0, 0x78ce54, 0x971240)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:342 +0x168
github.com/elves/elvish/eval.outputCaptureOp.Invoke(0x971240, 0xc420369fa0, 0x85b, 0x872, 0xc42028e000, 0x2, 0x4120e9, 0xc42055c9c0, 0x60, 0x0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:310 +0x5a
github.com/elves/elvish/eval.ValuesOp.Exec(0x9713a0, 0xc420369fc0, 0x85a, 0x873, 0xc42028e000, 0xc42004f420, 0x411be5, 0x7f8269cfabd8, 0x3f, 0xc42004f440)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:35 +0x51
github.com/elves/elvish/eval.compoundOp.Invoke(0x0, 0xc420369e00, 0x1, 0x1, 0xc42028e000, 0x412938, 0x10, 0x855840, 0xc4203d2201, 0xc4204cc5a0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:71 +0x7f
github.com/elves/elvish/eval.ValuesOp.Exec(0x971260, 0xc420369fe0, 0x85a, 0x873, 0xc42028e000, 0xc42044e240, 0xc42060fe70, 0xc42004f710, 0x79db2c, 0x8512e0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:35 +0x51
github.com/elves/elvish/eval.listOp.Invoke(0xc420369de0, 0x1, 0x1, 0xc42028e000, 0x77fb07, 0xc4205a87b0, 0xc4205a87b0, 0xc42044e240, 0xc42060fe70)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:286 +0x10e
github.com/elves/elvish/eval.ValuesOp.Exec(0x971360, 0xc420384000, 0x859, 0x874, 0xc42028e000, 0x12, 0x86dc20, 0xc4205a8798, 0x86dc20, 0xc42044e230)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:35 +0x51
github.com/elves/elvish/eval.compoundOp.Invoke(0x7f8269d3a000, 0xc420369dc0, 0x1, 0x1, 0xc42028e000, 0x60, 0xc42004fa88, 0x442985, 0x413737, 0xc42018d2f0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:71 +0x7f
github.com/elves/elvish/eval.ValuesOp.Exec(0x971260, 0xc420384020, 0x859, 0x874, 0xc42028e000, 0x1, 0x1, 0x1, 0x0, 0x1)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:35 +0x51
github.com/elves/elvish/eval.(*compiler).form.func1(0xc42028e000, 0xc4201d79a0, 0x0, 0x8524e0, 0x1, 0xbea058)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:220 +0x12e
github.com/elves/elvish/eval.funcValuesOp.Invoke(0xc42036f030, 0xc42028e000, 0x42a4d9, 0xc4201d79d0, 0xc42004fbe0, 0x20, 0xc42004fbd8)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:573 +0x30
github.com/elves/elvish/eval.ValuesOp.Exec(0x971340, 0xc42036f030, 0xffffffffffffffff, 0xffffffffffffffff, 0xc42028e000, 0xc42004fc98, 0x0, 0x0, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_value.go:35 +0x51
github.com/elves/elvish/eval.(*assignmentOp).Invoke(0xc42037ade0, 0xc42028e000, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:411 +0x1f4
github.com/elves/elvish/eval.Op.Exec(0x970400, 0xc42037ade0, 0x850, 0xffffffffffffffff, 0xc42028e000, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:30 +0x4d
github.com/elves/elvish/eval.(*formOp).Invoke(0xc420371930, 0xc42028e000, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:362 +0xac1
github.com/elves/elvish/eval.Op.Exec(0x9704a0, 0xc420371930, 0x850, 0x874, 0xc42028e000, 0x1000, 0x1000)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:30 +0x4d
github.com/elves/elvish/eval.(*Frame).Eval(0xc42028e000, 0x9704a0, 0xc420371930, 0x850, 0x874, 0x0, 0x0)
/home/user/.go/src/github.com/elves/elvish/eval/frame.go:129 +0xa2
github.com/elves/elvish/eval.(*pipelineOp).Invoke.func1(0xc42028e000, 0x9704a0, 0xc420371930, 0x850, 0x874, 0xc42018d2b8, 0xc42023cf10, 0x1)
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:118 +0x60
created by github.com/elves/elvish/eval.(*pipelineOp).Invoke
/home/user/.go/src/github.com/elves/elvish/eval/compile_op.go:117 +0x18d
@xiaq
Copy link
Member

xiaq commented Sep 23, 2018

Aha, you found a concurrency bug.

This is happening because we use maps for scopes in Elvish, and since pipelines are executed in parallel, this line will both read and write to the scope:

for i $input { print $i"\x00" }| output = [(fzf --read0 -f $pattern)];

The read comes from $input while the write comes from the assignment to output.

I have failed to construct a smallest reproduction though. This code should trigger the same crash, but I haven't succeeded yet:

@a = (range 1000)
for _ $@ { } | @b = (all)

@xiaq xiaq changed the title Crash in location mode Crash when accessing the local scope concurrently in a pipeline Sep 23, 2018
@xiaq
Copy link
Member

xiaq commented Sep 23, 2018

Meanwhile, you can workaround the problem by moving the output construct up one level:

edit:location:matcher = [pattern]{
  input = []
  each [in]{ input = [ $@input $in ] }
  output = [(for i $input {
    print $i"\x00"
  }| fzf --read0 -f $pattern)]
  for i $input {
    has-value $output $i
  }
}

Also, you can use all to capture all inputs, and use @a = xxx to replace a = [xxx]:

edit:location:matcher = [pattern]{
  @input = (all)
  @output = (for i $input { print $i"\x00" }| fzf --read0 -f $pattern)
  for i $input {
    has-value $output $i
  }
}

xiaq added a commit that referenced this issue Jan 14, 2020
The test now fails with "go test -race".
@xiaq
Copy link
Member

xiaq commented Jan 14, 2020

I don't have a reproduction locally, but at least I have a test that now fails when run with go test -race.

@xiaq xiaq changed the title Crash when accessing the local scope concurrently in a pipeline Crash when creating and reading local variable concurrently Jan 14, 2020
@xiaq
Copy link
Member

xiaq commented Mar 29, 2020

I believe this issue was fixed in 8c71635. Since I haven't been able to reproduce this locally and can't verify it, please reopen if this still reproduces.

@xiaq xiaq closed this as completed Mar 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants