Cryptic panic when livereload server fails to start
- Dominant language
- JavaScript
- Stars
- 5.6k
- Forks
- 175
- PR merge metrics
- No merged PRs in 30d
Description
There's a couple issues here that need to be fixed:
1. For some reason the hot reload port wasn't released, despite the application port being released. I'm not able to reproduce this behavior at the moment, so let's just keep an eye on it for now.
2. Nil pointer panic on *exe.Close
```
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xa0 pc=0x148aa70]
goroutine 66 [running]:
github.com/livebud/bud/package/exe.(*Cmd).Close(0x0)
/Users/m/dev/src/github.com/livebud/bud/package/exe/command.go:24 +0x70
panic({0x151a1a0, 0x19de710})
/usr/local/go/src/runtime/panic.go:838 +0x207
os/exec.(*Cmd).Wait(0x173cec0?)
/usr/local/go/src/os/exec/exec.go:499 +0x18
github.com/livebud/bud/package/exe.(*Cmd).Wait(...)
/Users/m/dev/src/github.com/livebud/bud/package/exe/command.go:39
github.com/livebud/bud/runtime/command/run.(*Command).startApp(0xc000256f60, {0x173cec0?, 0xc00024d300}, 0xc000243490)
/Users/m/dev/src/github.com/livebud/bud/runtime/command/run/run.go:115 +0x3c5
github.com/livebud/bud/runtime/command/run.(*Command).Run.func2()
/Users/m/dev/src/github.com/livebud/bud/runtime/command/run/run.go:37 +0x29
golang.org/x/sync/errgroup.(*Group).Go.func1()
/Users/m/dev/pkg/mod/golang.org/x/sync@v0.0.0-20220513210516-0976fa681c29/errgroup/errgroup.go:74 +0x64
created by golang.org/x/sync/errgroup.(*Group).Go
/Users/m/dev/pkg/mod/golang.org/x/sync@v0.0.0-20220513210516-0976fa681c29/errgroup/errgroup.go:71 +0xa5
```
The problem is that `process` is nil for some reason when calling the following: https://github.com/livebud/bud/blob/63900d258ae92faa4faf14e834021347f202d8a1/runtime/command/run/run.go#L75
3. Need a better error for unable to start the live reload server. Perhaps:
```go
fmt.Errorf("Error starting the live reload server on %s: %w", address, err)
```
Eventually, I'd like to find a free port and propagate the change accordingly, but for now, I think we just supply a better error.
## Steps to reproduce
1. This can be reproduced by altering the following:
https://github.com/livebud/bud/blob/63900d258ae92faa4faf14e834021347f202d8a1/runtime/command/run/run.go#L117-L120
```diff
func (c *Command) startHot(ctx context.Context, hotServer *hot.Server) error {
// TODO: host should be dynamic
+ return fmt.Errorf("failed to listen")
- return hotServer.ListenAndServe(ctx, "127.0.0.1:35729")
}
```
2. Within the bud repository, call `go run main.go -C examples/hn run`
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with runtime/command/run/run.go, especially startApp, startHot, and the linked process setup, then inspect package/exe/command.go for Close and Wait. Reproduce the failure with `go run main.go -C examples/hn run` after making the documented startHot change. Done means a failed live-reload startup reports a useful error without causing a nil-pointer panic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend, cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100