realize icon indicating copy to clipboard operation
realize copied to clipboard

Realize is not killing the current app

Open L4B0MB4 opened this issue 6 years ago • 5 comments

Currently when you build a webserver in go, realize will not restart the app on change but will run the new one in parallel.

Expected: When you change an app and the original is still running, realize should stop the old version and start the new version

Actual Behaviour Realize runs old and new versions of the app in parallel.

Reproduction main.go

package main

import (
	"fmt"
	"log"
	"net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
	ImportMe()
	fmt.Fprintf(w, "Hi there, I love %s!", r.URL)
}

func main() {
	http.HandleFunc("/", handler)
	log.Fatal(http.ListenAndServe(":8080", nil))

}

.realize.yaml

settings:
  legacy:
    force: true
    interval: 0s
schema:
  - name: go-server
    path: .
    commands:
      clean:
        status: true
      install:
        status: true
      build:
        status: true
      run:
        status: true
        method: go-server.exe
    watcher:
      extensions:
        - go
      paths:
        - /
      ignored_paths:
        - .git
        - .realize
        - vendor

Now start realize with "realize start". [13:56:23][GO-SERVER] : Install started [13:56:24][GO-SERVER] : Install completed in 1.671 s [13:56:24][GO-SERVER] : Build started [13:56:26][GO-SERVER] : Build completed in 1.634 s [13:56:26][GO-SERVER] : Running..

Change something in your go-code [13:56:23][GO-SERVER] : Install started [13:56:24][GO-SERVER] : Install completed in 1.671 s [13:56:24][GO-SERVER] : Build started [13:56:26][GO-SERVER] : Build completed in 1.634 s [13:56:26][GO-SERVER] : Running.. [13:56:57][GO-SERVER] : GO changed D:\go-server\main.go [13:56:58][GO-SERVER] : Install started [13:56:59][GO-SERVER] : Install completed in 1.291 s [13:57:00][GO-SERVER] : Build started [13:57:01][GO-SERVER] : Build completed in 1.591 s [13:57:01][GO-SERVER] : Running.. [13:57:01][GO-SERVER] : 2019/05/17 13:57:01 listen tcp :8080: bind: Normalerweise darf jede Socketadresse (Protokoll, Netzwerkadresse oder Anschluss) nur jeweils einmal verwendet werden.

Translation for last line: " Normaly each socket adress should only be used once"

L4B0MB4 avatar May 17 '19 12:05 L4B0MB4

Please let me know if I´m missing a command that changes this behaviour

L4B0MB4 avatar May 17 '19 12:05 L4B0MB4

I am having a same problem. Hopefully author will fix this.

pavles6 avatar Jun 02 '19 15:06 pavles6

I too am having the same problem. My app runs a webserver and also runs workers that wait to finish jobs before exiting when requested to exit. So what ends up happening is the newly built version runs before the previous command has exited cleanly, and my app complains that the http port is already in use and fails.

Given that I want my jobs to complete and not have the app killed forcefully, perhaps realize could make sure the previous command has ended before starting a new one. A config setting for the termination type, forceful or clean might be useful?

jc21 avatar Jul 09 '19 23:07 jc21

Same issue here

pedrofaria avatar Sep 16 '19 13:09 pedrofaria

Well after some time on research, I figure out a workaround to fix this problem. Basically you need to run a command every restart.

Inside a linux container, I did this with my .realize.yaml file:

# ...
  watcher:
    scripts:
    - type: before
      command: pkill server-api
      output: true

pedrofaria avatar Sep 17 '19 09:09 pedrofaria