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 generate with watch and hot reload starts server after cancelling again and doesn't clean up #464

Closed
stefanohrmann opened this issue Jan 26, 2024 · 2 comments
Labels
bug Something isn't working cmd

Comments

@stefanohrmann
Copy link

stefanohrmann commented Jan 26, 2024

I followed the instruction for Hot Reload in you guide and after the release of v0.2.543 when i run the built in mode with:

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

then after cancelling/stopping the watch mode with Ctrl+C a production build is started and after this the --cmd is executed again and in my case starts the server again.

I created a simple application to show the issue: templ-watch-issue.zip

With this example i get the following output:

stefan@home:~/Projekte/go/tests/templ-watch-issue$ templ generate --watch --proxy="http://localhost:8081" --cmd="go run ."
Processing path: /home/stefan/Projekte/go/tests/templ-watch-issue
Generating dev code: /home/stefan/Projekte/go/tests/templ-watch-issue
(✓) Generated code for "/home/stefan/Projekte/go/tests/templ-watch-issue/main.templ" in 767.498µs
(✓) Generated code for 1 templates with 0 errors in 879.651µs
Executing command: go run .
Proxying from http://127.0.0.1:7331 to target: http://localhost:8081
Opening URL: http://localhost:8081

   ____    __
  / __/___/ /  ___
 / _// __/ _ \/ _ \
/___/\__/_//_/\___/ v4.11.4
High performance, minimalist Go web framework
https://echo.labstack.com
____________________________________O/_______
                                    O\
⇨ http server started on [::]:8081
^CStopping...
Generating production code: /home/stefan/Projekte/go/tests/templ-watch-issue
(!) Deleted file "/home/stefan/Projekte/go/tests/templ-watch-issue/main_templ.txt"
(✓) Generated code for "/home/stefan/Projekte/go/tests/templ-watch-issue/main.templ" in 687.207µs
(✓) Generated code for 1 templates with 0 errors in 798.799µs
Executing command: go run .
stefan@home:~/Projekte/go/tests/templ-watch-issue$ 
   ____    __
  / __/___/ /  ___
 / _// __/ _ \/ _ \
/___/\__/_//_/\___/ v4.11.4
High performance, minimalist Go web framework
https://echo.labstack.com
____________________________________O/_______
                                    O\
⇨ http server started on [::]:8081

I can then try to stop the second launch of the server with Ctrl+C, but in this case only templ is stopped and server still lingers in the background:

stefan@home:~/Projekte/go/tests/templ-watch-issue$ netstat -tlpn
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp6       0      0 :::8081                 :::*                    LISTEN      197863/templ-watch- 

Two things i noticed by looking in the source code and the trace above:

  1. The temporary text files are deleted by the "Generating production code" not after watch was stopped.
  2. As far as i understand the run code the next run kills the previous run and not the stopping of the program with Ctrl+C.
@a-h
Copy link
Owner

a-h commented Jan 29, 2024

Yes, I saw this during my testing of the rewrite. Sorry about that. I think I've resolved it in these lines:

https://github.com/a-h/templ/pull/470/files#diff-d871fda4ab49b4f5e6475e42ebccf5ca92261a30588f3d5165132dbe769587e1R270-R275

If you'd like to review the PR, that would be great. I think the logic in the new version is clearer. I've explained it here: #470 (comment)

@joerdav joerdav added bug Something isn't working cmd labels Jan 29, 2024
@joerdav joerdav changed the title templ generate with watch and hot reload starts server after cancelling again and doesn't clean up cmd: templ generate with watch and hot reload starts server after cancelling again and doesn't clean up Jan 29, 2024
@joerdav
Copy link
Collaborator

joerdav commented Jan 30, 2024

Fixed in #470 please feel free to reopen if the issue persists.

@joerdav joerdav closed this as completed Jan 30, 2024
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
Projects
None yet
Development

No branches or pull requests

3 participants