kcl-lang / cli

The KCL Command Line Interface (CLI).
https://kcl-lang.io
Apache License 2.0
19 stars 14 forks source link

KCL panics when trying to write files that are being watched #114

Closed wmcnamee-coreweave closed 3 months ago

wmcnamee-coreweave commented 3 months ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

I have tilt watching files and reapplying them to kubernetes. When I try to regenerate those files with KCL, I get a race condition sometimes where KCL panics and crashes. Simply rerunning enough times will get past the panic.

2. What did you expect to see? (Required)

no errors

3. What did you see instead (Required)

panic: {"code":-32603,"message":"write |1: file already closed"}

goroutine 1 [running]:
kcl-lang.io/kcl-go/pkg/runtime.initRuntime(0x0?)
    /home/runner/go/pkg/mod/kcl-lang.io/kcl-go@v0.9.3/pkg/runtime/init.go:57 +0x3a4
kcl-lang.io/kcl-go/pkg/runtime.GetRuntime.func1()
    /home/runner/go/pkg/mod/kcl-lang.io/kcl-go@v0.9.3/pkg/runtime/init.go:26 +0x20
sync.(*Once).doSlow(0x1?, 0x1049b0438?)
    /opt/hostedtoolcache/go/1.22.5/x64/src/sync/once.go:74 +0x100
sync.(*Once).Do(...)
    /opt/hostedtoolcache/go/1.22.5/x64/src/sync/once.go:65
kcl-lang.io/kcl-go/pkg/runtime.GetRuntime()
    /home/runner/go/pkg/mod/kcl-lang.io/kcl-go@v0.9.3/pkg/runtime/init.go:26 +0x40
kcl-lang.io/kcl-go/pkg/service.NewKclvmServiceClient(...)
    /home/runner/go/pkg/mod/kcl-lang.io/kcl-go@v0.9.3/pkg/service/client_kclvm_service.go:22
kcl-lang.io/kcl-go/pkg/kcl.Service(...)
    /home/runner/go/pkg/mod/kcl-lang.io/kcl-go@v0.9.3/pkg/kcl/service.go:12
kcl-lang.io/kcl-go/pkg/kcl.runWithHooks({0x14000af5658, 0x0, 0x0}, {0x10cf60cc0, 0x1, 0x1}, {0x14000af5728, 0x1, 0x1})
    /home/runner/go/pkg/mod/kcl-lang.io/kcl-go@v0.9.3/pkg/kcl/api.go:436 +0xf8
kcl-lang.io/kcl-go/pkg/kcl.run(...)
    /home/runner/go/pkg/mod/kcl-lang.io/kcl-go@v0.9.3/pkg/kcl/api.go:445
kcl-lang.io/kcl-go/pkg/kcl.RunWithOpts({0x14000af5728?, 0x14000160240?, 0x0?})
    /home/runner/go/pkg/mod/kcl-lang.io/kcl-go@v0.9.3/pkg/kcl/api.go:372 +0x50
kcl-lang.io/kpm/pkg/client.(*KpmClient).Run.func1(0x14000160240)
    /home/runner/go/pkg/mod/kcl-lang.io/kpm@v0.9.2/pkg/client/run.go:542 +0x2c4
kcl-lang.io/kpm/pkg/client.(*PkgVisitor).Visit(0x1400012a1e8, 0x0?, 0x140006beed0)
    /home/runner/go/pkg/mod/kcl-lang.io/kpm@v0.9.2/pkg/client/visitor.go:52 +0x70
kcl-lang.io/kpm/pkg/client.(*KpmClient).Run(0x14000460ea0, {0x14000af5aa0, 0xd, 0x14000128a80?})
    /home/runner/go/pkg/mod/kcl-lang.io/kpm@v0.9.2/pkg/client/run.go:517 +0x214
kcl-lang.io/cli/pkg/options.(*RunOptions).Run(0x14000002ea0)
    /home/runner/work/cli/cli/pkg/options/run.go:117 +0x368
kcl-lang.io/cli/cmd/kcl/commands.NewRunCmd.func1(0x14000141b00?, {0x14000128a70?, 0x4?, 0x10633bc45?})
    /home/runner/work/cli/cli/cmd/kcl/commands/run.go:58 +0x4c
github.com/spf13/cobra.(*Command).execute(0x140006d5208, {0x1400004e110, 0x1, 0x1})
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:985 +0x840
github.com/spf13/cobra.(*Command).ExecuteC(0x140006d5208)
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:1117 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:1041
kcl-lang.io/cli/cmd/kcl/commands.executeRunCmd({0x1400004e110, 0x1, 0x1})
    /home/runner/work/cli/cli/cmd/kcl/commands/plugin.go:17 +0x6c
kcl-lang.io/cli/cmd/kcl/commands.bootstrapCmdPlugin(0x140005d4308?, {0x1071f0550, 0x14000172930})
    /home/runner/work/cli/cli/cmd/kcl/commands/plugin.go:67 +0x414
kcl-lang.io/cli/cmd/kcl/commands.New()
    /home/runner/work/cli/cli/cmd/kcl/commands/root.go:126 +0x36c
main.main()
    /home/runner/work/cli/cli/cmd/kcl/main.go:14 +0x1c
make: *** [generate] Error 2

4. What is your KCL components version? (Required)

0.9.3
Peefy commented 3 months ago

Hello! Thank you for your feedback. Could you please let me know what your operating system is?

Peefy commented 3 months ago

Do you mean this issue? https://github.com/kcl-lang/kcl-go/actions/runs/10069602729/job/27836836253?pr=354 and I will fix it soon in KCL v0.10.0-alpha.1