d2: [v0.6.3]windows d2.exe -w is crashed.
d2.exe -w “sandbox.d2” “sandbox.svg”
‘detected change’ occurs frequently. i did not save ‘sandbox.d2’. (only the first time) ‘d2.exe’ sometimes crashed.
[34minfo[0m: broadcasting update to 1 client
[34minfo[0m: detected change in sandbox.svg: recompiling...
[32msuccess[0m: successfully compiled sandbox.d2 to sandbox.svg in 103.344ms
[34minfo[0m: broadcasting update to 1 client
[34minfo[0m: detected change in sandbox.svg: recompiling...
[32msuccess[0m: successfully compiled sandbox.d2 to sandbox.svg in 125.8546ms
[34minfo[0m: broadcasting update to 1 client
[34minfo[0m: detected change in sandbox.svg: recompiling...
[32msuccess[0m: successfully compiled sandbox.d2 to sandbox.svg in 95.0012ms
[34minfo[0m: broadcasting update to 1 client
[34minfo[0m: detected change in sandbox.svg: recompiling...
[32msuccess[0m: successfully compiled sandbox.d2 to sandbox.svg in 107.1851ms
[34minfo[0m: broadcasting update to 1 client
[34minfo[0m: detected change in sandbox.svg: recompiling...
[32msuccess[0m: successfully compiled sandbox.d2 to sandbox.svg in 102.4472ms
[34minfo[0m: broadcasting update to 1 client
[34minfo[0m: detected change in sandbox.svg: recompiling...
[32msuccess[0m: successfully compiled sandbox.d2 to sandbox.svg in 147.4784ms
[34minfo[0m: broadcasting update to 1 client
[34minfo[0m: detected change in sandbox.svg: recompiling...
[32msuccess[0m: successfully compiled sandbox.d2 to sandbox.svg in 88.3592ms
[34minfo[0m: broadcasting update to 1 client
[34minfo[0m: detected change in sandbox.svg: recompiling...
[32msuccess[0m: successfully compiled sandbox.d2 to sandbox.svg in 153.6542ms
[34minfo[0m: broadcasting update to 1 client
[34minfo[0m: detected change in sandbox.svg: recompiling...
[32msuccess[0m: successfully compiled sandbox.d2 to sandbox.svg in 87.7296ms
[34minfo[0m: broadcasting update to 1 client
[34minfo[0m: detected change in sandbox.svg: recompiling...
.
.
.
.
.
.
panic: runtime error: index out of range [0] with length 0
goroutine 13 [running]:
oss.terrastruct.com/d2/d2cli.(*watcher).watchLoop(0xc00007a1e0, {0x282ff88, 0xc000707c70})
oss.terrastruct.com/d2/d2cli/watch.go:297 +0xb7e
oss.terrastruct.com/d2/d2cli.(*watcher).goFunc.func1()
oss.terrastruct.com/d2/d2cli/watch.go:203 +0x76
created by oss.terrastruct.com/d2/d2cli.(*watcher).goFunc
oss.terrastruct.com/d2/d2cli/watch.go:199 +0x8d
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (5 by maintainers)
this have been fixed since
github.com/fsnotify/fsnotify@7086bea, but a patch version is not planned to be released.@alixander if you would like to bump the dependency version by that commit, this issue could be fixed.
Yes. The
fsnotifydoes handle file names internally on Windows. However, I believe it’sWatchListfunction’s misbehavior causing the issue.The codes introduces in this commit, which is also just the version where this issue got: v0.6.2
https://github.com/terrastruct/d2/commit/f328eb3b9f251a6fc198d89d201a0f1ea7c4075e#diff-fc70cf71bc274a18a06914bfd17d043d0cdc7795896c3f1abf9597d0340c0ef5L240-R255
Where it calls
fw.WatchList()and re-added the results to the watcher, but as we knew:So on Windows it’s adding the whole directory to the watch list, and caused the infinite loop of writing and notified and re-writing the svg file.
Could be a red herring, but the fsnotify watcher WatchList() function appears to be returning a different path depending on platform:
(Both results are from throwing a debug print in the pollTicker case of watch loop and running with “go run . -w test.d2 -d”)
Looks like at that point d2 is essentially watching for any change in the parent folder. Instead of the specified watch file. The d2 instance is then starting a new compile on all WRITE events even if it’s an output .svg.
Update: The above is reproducible in a new project with just fsnotify:
Prints: watch list: [C:\path\to]
I’ve also encountered this in v0.6.2 & 0.6.3 while v0.6.1 is fine. I did not even open any editor and just ran
d2 -w myfile.d2in the command line. Several seconds later it will say ‘detected change’ and recompile endlessly.