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

Panic on certain -source calls #1202

Closed
iwoloschin opened this issue Dec 26, 2020 · 8 comments
Closed

Panic on certain -source calls #1202

iwoloschin opened this issue Dec 26, 2020 · 8 comments

Comments

@iwoloschin
Copy link
Contributor

I'm getting a panic on starting a new elvish process, but only with @zzamboni's alias module loaded.

Elvish is built locally (via my update module):

~$ elvish -buildinfo
Version: v0.14.1-188-g719314c
Go version: go1.15.6
Reproducible build: true

If the alias module is used and any aliases are defined in ~/.elvish/aliases/ I get a panic:

~$ $ elvish
panic: runtime error: index out of range [4] with length 4

goroutine 300 [running]:
github.com/elves/elvish/pkg/eval.fnOp.exec(0x4, 0x152f580, 0xc0000d2460, 0xc0002eb7a0, 0x1, 0x1)
	github.com/elves/elvish/pkg/eval/builtin_special.go:188 +0x2d7
github.com/elves/elvish/pkg/eval.(*formOp).exec(0xc0000de210, 0xc0002eb7a0, 0x0, 0x0)
	github.com/elves/elvish/pkg/eval/compile_effect.go:341 +0xdf9
github.com/elves/elvish/pkg/eval.(*pipelineOp).exec.func1(0x152acc0, 0xc0000de210, 0xc0002eb7a0, 0xc000188288, 0xc00061c480, 0x17c3200)
	github.com/elves/elvish/pkg/eval/compile_effect.go:150 +0x3f
created by github.com/elves/elvish/pkg/eval.(*pipelineOp).exec
	github.com/elves/elvish/pkg/eval/compile_effect.go:149 +0x225

If I comment out the use line or remove all aliases from ~/.elvish/aliases/ the process starts up and appears to be fine.

@krader1961 suggests in the chat that this commit might be to blame. I don't think I'm familiar enough with go or Elvish internals to really have any idea.

@krader1961
Copy link
Contributor

I'm also seeing a panic, and I don't use @zzamboni's alias module. I update $-exports- directly in my ~/.elvish/rc.elv. Reverting the three most recent commits to 9a6d53e resolves the panic but results in this failure:

Exception: compilation error: cannot find variable $edit:insert:binding
[bundled readline-binding], line 2: b=[k f]{ edit:insert:binding[$k] = $f } {
/Users/krader/.elvish/rc.elv, line 18: use readline-binding

I have to revert the five most recent commits, back to 09829ae, to get a working interactive shell.

@krader1961
Copy link
Contributor

Commenting out my assignment to $-exports- yields a working shell that is built against the current master branch. So that experimental feature is the only obvious thing broken by those five commits. TBD is whether there is a simple fix to make that mechanism compatible with the recent changes or whether it is time to either a) make it no longer experimental (and add unit tests of its behavior), or b) replace it with a different mechanism.

@krader1961
Copy link
Contributor

FWIW, I'm seeing a different panic than @iwoloschin reported:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x136f2e6]

goroutine 13819 [running]:
github.com/elves/elvish/pkg/eval.(*Ns).lookup(0x0, 0xc00029f383, 0x5, 0xc000489658)
        /Users/krader/projects/3rd-party/elvish/pkg/eval/ns.go:68 +0x26
github.com/elves/elvish/pkg/eval.(*Ns).indexInner(...)
        /Users/krader/projects/3rd-party/elvish/pkg/eval/ns.go:60
github.com/elves/elvish/pkg/eval.deref(0xc000bb23f0, 0xc00042dc50, 0x0, 0x0)
        /Users/krader/projects/3rd-party/elvish/pkg/eval/var_ref.go:119 +0xf5
github.com/elves/elvish/pkg/eval.variableOp.exec(0x137d, 0x1388, 0x0, 0xc00029f37e, 0xa, 0
xc00042dc50, 0xc000bb23f0, 0x8, 0x4, 0x203000, ...)
        /Users/krader/projects/3rd-party/elvish/pkg/eval/compile_value.go:320 +0x4d
github.com/elves/elvish/pkg/eval.compoundOp.exec(0x137d, 0x1388, 0x0, 0xc000428b30, 0x1, 0
x1, 0xc000bb23f0, 0x14738c0, 0x145ed01, 0xc000bb0280, ...)
        /Users/krader/projects/3rd-party/elvish/pkg/eval/compile_value.go:75 +0x69
github.com/elves/elvish/pkg/eval.seqValuesOp.exec(0x137d, 0x1388, 0xc000428b20, 0x1, 0x1,
0xc000bb23f0, 0xc000ba3f20, 0xc000ba1d10, 0x1489f60, 0xc000ba1d10, ...)
        /Users/krader/projects/3rd-party/elvish/pkg/eval/compile_value.go:620 +0xb3
github.com/elves/elvish/pkg/eval.(*assignOp).exec(0xc000426740, 0xc000bb23f0, 0xc000489e38
, 0x0)
        /Users/krader/projects/3rd-party/elvish/pkg/eval/compile_lvalue.go:110 +0x232
github.com/elves/elvish/pkg/eval.(*formOp).exec(0xc000425340, 0xc000bb23f0, 0x0, 0x0)
        /Users/krader/projects/3rd-party/elvish/pkg/eval/compile_effect.go:398 +0x862
github.com/elves/elvish/pkg/eval.(*pipelineOp).exec.func1(0x152b360, 0xc000425340, 0xc000b
b23f0, 0xc000808748, 0xc0005c9510, 0xc00055aa00)
        /Users/krader/projects/3rd-party/elvish/pkg/eval/compile_effect.go:150 +0x3f
created by github.com/elves/elvish/pkg/eval.(*pipelineOp).exec
        /Users/krader/projects/3rd-party/elvish/pkg/eval/compile_effect.go:149 +0x225

@zzamboni
Copy link
Contributor

zzamboni commented Dec 26, 2020 via email

@zzamboni
Copy link
Contributor

So, more details:

> elvish -version
v0.14.0-182-g719314c0
> elvish
panic: runtime error: index out of range [4] with length 4

goroutine 575 [running]:
github.com/elves/elvish/pkg/eval.fnOp.exec(0x4, 0x152f700, 0xc00014d0e0, 0xc000444e70, 0x1, 0x1)
	github.com/elves/elvish/pkg/eval/builtin_special.go:188 +0x2d7
github.com/elves/elvish/pkg/eval.(*formOp).exec(0xc0004ae210, 0xc000444e70, 0x0, 0x0)
	github.com/elves/elvish/pkg/eval/compile_effect.go:341 +0xdf9
github.com/elves/elvish/pkg/eval.(*pipelineOp).exec.func1(0x152ae40, 0xc0004ae210, 0xc000444e70, 0xc00028c188, 0xc00009f0b0, 0x17c4200)
	github.com/elves/elvish/pkg/eval/compile_effect.go:150 +0x3f
created by github.com/elves/elvish/pkg/eval.(*pipelineOp).exec
	github.com/elves/elvish/pkg/eval/compile_effect.go:149 +0x225
Exception: elvish exited with 2
[tty 25], line 1: elvish

Commenting out -exports- as @krader1961 suggested still gives me the same panic, but moving my whole configuration aside gives me a working shell:

[~]|> mv .elvish .elvish-bak
[~]|> elvish
~> 

I'll explore further to try and determine which part is causing the panic.

@zzamboni
Copy link
Contributor

I can confirm that just loading my alias module (even without defining any aliases) triggers the panic. I commented out all use of the alias module, which gives me a working shell, but then loading it interactively:

[~/.elvish]─[⎇ master]─[●]|> elvish
[~/.elvish]─[⎇ master]─[●]|> use github.com/zzamboni/elvish-modules/alias
panic: runtime error: index out of range [4] with length 4

goroutine 15133 [running]:
github.com/elves/elvish/pkg/eval.fnOp.exec(0x4, 0x152f700, 0xc0008c7f40, 0xc000a8f500, 0x148f880, 0x1)
	github.com/elves/elvish/pkg/eval/builtin_special.go:188 +0x2d7
github.com/elves/elvish/pkg/eval.(*formOp).exec(0xc000e12a50, 0xc000a8f500, 0x0, 0x0)
	github.com/elves/elvish/pkg/eval/compile_effect.go:341 +0xdf9
github.com/elves/elvish/pkg/eval.(*pipelineOp).exec.func1(0x152ae40, 0xc000e12a50, 0xc000a8f500, 0xc0000a32c0, 0xc0003720f0, 0x0)
	github.com/elves/elvish/pkg/eval/compile_effect.go:150 +0x3f
created by github.com/elves/elvish/pkg/eval.(*pipelineOp).exec
	github.com/elves/elvish/pkg/eval/compile_effect.go:149 +0x225
Exception: elvish exited with 2

@zzamboni
Copy link
Contributor

Upon further experimentation, the panic seems to be happening when the alias:-load-alias function is called. I modified alias:def to just print the arguments with which it calls -load-alias, so I could test them by hand:

[~]|> elvish
[~]|> ls .elvish/aliases
".elvish/aliases": No such file or directory (os error 2)
[~]|> use github.com/zzamboni/elvish-modules/alias
[~]|> alias:new foo echo bar
foo /Users/taazadi1/.elvish/aliases/foo.elv

Running the commands from -load-alias by hand works fine, however when calling the function, it still panics:

[~]|> name = foo
[~]|> file = /Users/taazadi1/.elvish/aliases/foo.elv
[~]|> aliases = [&]
[~]|> nop $aliases
[~]|> -source $file
[~]|> -tmpfile = (mktemp)
[~]|> echo 'aliases['$name'] = $'$name'~' > $-tmpfile
[~]|> cat $-tmpfile
aliases[foo] = $foo~
[~]|> -source $-tmpfile
[~]|> rm -f $-tmpfile
[~]|> # So far so good - ran all the commands from alias:-load-alias
[~]|> # However...
[~]|> alias:-load-alias foo /Users/taazadi1/.elvish/aliases/foo.elv
panic: runtime error: index out of range [4] with length 4

goroutine 167522 [running]:
github.com/elves/elvish/pkg/eval.fnOp.exec(0x4, 0x152f700, 0xc000bfc000, 0xc0003d4ee0, 0x1, 0x1)
	github.com/elves/elvish/pkg/eval/builtin_special.go:188 +0x2d7
github.com/elves/elvish/pkg/eval.(*formOp).exec(0xc000e6e210, 0xc0003d4ee0, 0x0, 0x0)
	github.com/elves/elvish/pkg/eval/compile_effect.go:341 +0xdf9
github.com/elves/elvish/pkg/eval.(*pipelineOp).exec.func1(0x152ae40, 0xc000e6e210, 0xc0003d4ee0, 0xc0000a21d8, 0xc0009fc120, 0x17c4200)
	github.com/elves/elvish/pkg/eval/compile_effect.go:150 +0x3f
created by github.com/elves/elvish/pkg/eval.(*pipelineOp).exec
	github.com/elves/elvish/pkg/eval/compile_effect.go:149 +0x225
Exception: elvish exited with 2

@xiaq any ideas?

@xiaq xiaq changed the title Panic on Start Panic on certain -source calls Dec 26, 2020
@xiaq
Copy link
Member

xiaq commented Dec 26, 2020

I broke -source, and the reproduction of the bug has several conditions:

  • -source must be called from within a function;
  • The sourced file must define a new binding;
  • The function must capture a variable from the outer scope.

A minimal repro:

~> a = foo
~> cat > b.elv
b = bar
~> { nop $a; -source b.elv }
# crash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants