rjkroege / edwood

Go version of Plan9 Acme Editor
Other
385 stars 34 forks source link

Crash due to index out of range while writing to data file #265

Open fhs opened 5 years ago

fhs commented 5 years ago

Edwood crashed while doing a Put on a .go file. Most likely the crash happened when Put triggered acme-lsp to format the .go file and show diagnostics.

panic: runtime error: index out of range [5] with length 5

goroutine 199 [running]:
panic(0x8f4fa0, 0xc00028cae0)
    /home/big/go/src/runtime/panic.go:722 +0x2c2 fp=0xc0004a9b20 sp=0xc0004a9a90 pc=0x430902
runtime.goPanicIndex(0x5, 0x5)
    /home/big/go/src/runtime/panic.go:75 +0xa3 fp=0xc0004a9b68 sp=0xc0004a9b20 pc=0x42ee83
main.(*Column).Grow(0xc0000bc840, 0xc0001eec00, 0x1)
    /home/fhs/go/pkg/mod/github.com/rjkroege/edwood@v0.2.1-0.20190720111259-5d2e2ade1830/col.go:488 +0x114c fp=0xc0004a9cf0 sp=0xc0004a9b68 pc=0x7f3d2c
main.(*Text).Show(0xc0001eed18, 0x0, 0x0, 0x0)
    /home/fhs/go/pkg/mod/github.com/rjkroege/edwood@v0.2.1-0.20190720111259-5d2e2ade1830/text.go:1222 +0x39c fp=0xc0004a9d70 sp=0xc0004a9cf0 pc=0x81fd4c
main.xfidwrite(0xc0000bcb00)
    /home/fhs/go/pkg/mod/github.com/rjkroege/edwood@v0.2.1-0.20190720111259-5d2e2ade1830/xfid.go:577 +0xa6e fp=0xc0004a9f88 sp=0xc0004a9d70 pc=0x82b21e
main.xfidctl(0xc0000bcb00, 0x9e5960, 0xc0000f60d0)
    /home/fhs/go/pkg/mod/github.com/rjkroege/edwood@v0.2.1-0.20190720111259-5d2e2ade1830/xfid.go:52 +0x9c fp=0xc0004a9fc8 sp=0xc0004a9f88 pc=0x8286cc
runtime.goexit()
    /home/big/go/src/runtime/asm_amd64.s:1357 +0x1 fp=0xc0004a9fd0 sp=0xc0004a9fc8 pc=0x460911
created by main.xfidallocthread
    /home/fhs/go/pkg/mod/github.com/rjkroege/edwood@v0.2.1-0.20190720111259-5d2e2ade1830/acme.go:624 +0x1d4

Full stack trace: edwood_crash.txt

fhs commented 5 years ago

I can reproduce this after putting a 5 seconds sleep before the loop where we're getting the "index out of range" panic in Column.Grow. Follow these steps to reproduce:

  1. Open acme with only one column.
  2. Open few windows. Let's call the topmost window T. Make sure nothing in the window body is showing (t.fr.GetFrameFillStatus().Maxlines == 0).
  3. This will trigger xfidwrite to call Text.Show, which will call Column.Grow:
    echo -n '#0' | 9p write acme/T/addr
    echo hello | 9p write acme/T/data
  4. Before the 5 seconds expire, create a new window with B some_file_not_open_yet. The crash will happen when the 5 seconds expire.

Basically, the crash is happening when we create a new window in a column while we're growing another window within the same column.

rjkroege commented 5 years ago

This seems similar to #57? Column changes while a window is being written to over the file system is suspect.