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

cmd: templ --watch does not close port on SIGINT #487

Closed
Murderlon opened this issue Feb 2, 2024 · 10 comments
Closed

cmd: templ --watch does not close port on SIGINT #487

Murderlon opened this issue Feb 2, 2024 · 10 comments
Labels
bug Something isn't working cmd NeedsInvestigation Issue needs some investigation before being fixed

Comments

@Murderlon
Copy link

Hi, I love the effort in bringing a watcher to templ! Unfortunately, the port of my server is never closed.

I'm running a practically barebones chi server, nothing special going on there.

  • macOS Sonoma 14.2.1
  • go version go1.21.5 darwin/arm64
  • templ v0.2.543
λ templ generate --watch --proxy="http://localhost:3000" --cmd="go run ."                   

Processing path: /Users/merlijnvos/code/the-boring-stack
Generating dev code: /Users/merlijnvos/code/the-boring-stack
(✓) Generated code for "/Users/merlijnvos/code/the-boring-stack/views/layout.templ" in 1.523417ms
(✓) Generated code for "/Users/merlijnvos/code/the-boring-stack/views/index.templ" in 1.572042ms
(✓) Generated code for 2 templates with 0 errors in 2.030583ms
Executing command: go run .
Proxying from http://127.0.0.1:7331 to target: http://localhost:3000
Opening URL: http://localhost:3000
2024-02-02 15:04:06 INF starting server port=:3000
^CStopping...
Generating production code: /Users/merlijnvos/code/the-boring-stack
(!) Deleted file "/Users/merlijnvos/code/the-boring-stack/views/index_templ.txt"
(!) Deleted file "/Users/merlijnvos/code/the-boring-stack/views/layout_templ.txt"
(✓) Generated code for "/Users/merlijnvos/code/the-boring-stack/views/index.templ" in 2.432458ms
(✓) Generated code for "/Users/merlijnvos/code/the-boring-stack/views/layout.templ" in 2.350875ms
(✓) Generated code for 2 templates with 0 errors in 4.017542ms
Executing command: go run .

λ 2024-02-02 15:04:17 INF starting server port=:3000                                                                 

☝️ notice that the program stopped but it logged a line where my cursor is

Running it again:

λ templ generate --watch --proxy="http://localhost:3000" --cmd="go run ."                                        

Processing path: /Users/merlijnvos/code/the-boring-stack
Generating dev code: /Users/merlijnvos/code/the-boring-stack
(✓) Generated code for "/Users/merlijnvos/code/the-boring-stack/views/layout.templ" in 1.751917ms
(✓) Generated code for "/Users/merlijnvos/code/the-boring-stack/views/index.templ" in 1.754292ms
(✓) Generated code for 2 templates with 0 errors in 2.152833ms
Executing command: go run .
Proxying from http://127.0.0.1:7331 to target: http://localhost:3000
Opening URL: http://localhost:3000
2024-02-02 15:05:25 INF starting server port=:3000
listen tcp :3000: bind: address already in use
exit status 1
@Murderlon Murderlon changed the title temple --watch does not close port on SIGINT templ --watch does not close port on SIGINT Feb 2, 2024
@joerdav joerdav changed the title templ --watch does not close port on SIGINT cmd: templ --watch does not close port on SIGINT Feb 2, 2024
@joerdav joerdav added bug Something isn't working cmd NeedsInvestigation Issue needs some investigation before being fixed labels Feb 2, 2024
@a-h
Copy link
Owner

a-h commented Feb 2, 2024

Would you mind giving the main branch a try please? I completely rewrote the whole of the generate --watch command in #470 but we haven't cut a new release yet.

@Huzaifa-MS
Copy link

Huzaifa-MS commented Feb 6, 2024

Coming from #493
I tested on wsl on windows
using go: upgraded github.com/a-h/templ v0.2.543 => v0.2.544-0.20240205222607-1e6a80f83c3a
with command: /home/huz/go/bin/templ generate --watch --proxy=http://127.0.0.1:8080 --proxyport=8081 --cmd="go run ."

TLDR: Does not work. Spawns a new cmd after closing templ. claimed evidence is changed id of go process after ctrl+z

It seems that the templ process on ctrl+c is closing itself and the go process it started however after that it create a new go process? I say this based on the fact a the pgid and id of the go process has changed after I pressed ctrl+c to terminate.

proof-templ

aside: I ran into this issue when I was trying to run templ using custom hotreload go file and ran into this issue on linux. for some reason I can easily kill the command in windows using my custom hotreload

@a-h
Copy link
Owner

a-h commented Feb 6, 2024

Hi @Huzaifa-MS, from the logs you posted, it looks like you're not using the latest version of the CLI on the main branch.

Would you be able to test it with the main branch instead please? I've rewritten the whole of the --watch mode code from scratch since the version you're using.

@Huzaifa-MS
Copy link

I will try. Sorry I thought doing a go get to main would get the latest

@Huzaifa-MS
Copy link

It seems the latest version of templ requires a newer version of go since my version does not have slog. Will try this later today hopefully

@Huzaifa-MS
Copy link

It is working correctly now. Great work! :)

Steps:
*New Templ Repo needs slog to compile meaning it needs a Go version which has this. My previous version 1.20 did not have it.

  1. git clone https://github.com/a-h/templ.git
  2. cd templ/cmd/templ
  3. go build
  4. go install.
  5. templ version #should be 2.560 or greater
    *go get -u no longer works as in installing package from what I understand in newer go versions

Here is the screenshot:

proof-templ-2

Also how would I fix the generator warning? or will updating to next release fix itself

@a-h
Copy link
Owner

a-h commented Feb 7, 2024

It should fix itself in the next release.

With Go, when you do go get -u github.com/a-h/templ it installs the latest tag, based on a semantic version, e.g. v0.0.450.

If you run go get -u github.com/a-h/templ@<commithash> it installs that specific version.

You don't need Go 1.21 installed to run the CLI, if you use a binary that we release, but obviously, if you build from source, you'll need the later Go version.

The strategy we have is to use the latest Go version to build the CLI and produce binaries, but the runtime supports the current Go version - 2 releases. Go 1.22 was released today, so we're now free to start using Go 1.20 features in the runtime.

@Huzaifa-MS
Copy link

Thank you for helping me understand this better : )

@a-h
Copy link
Owner

a-h commented Mar 4, 2024

@Murderlon - the latest release of templ should have fixed this issue. If not, please feel free to reopen, and I'll start investigation again, but here's a demo of it working fine, with the example chi project in the templ repo.

sorted_small.mp4

@a-h a-h closed this as completed Mar 4, 2024
@Murderlon
Copy link
Author

Sorry I didn't get around to testing this earlier myself. Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cmd NeedsInvestigation Issue needs some investigation before being fixed
Projects
None yet
Development

No branches or pull requests

4 participants