Skip to content

Commit

Permalink
cmd/vinegar: properly kill roblox when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Sep 22, 2024
1 parent f231e73 commit 7ebad34
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions cmd/vinegar/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ import (

const (
LogTimeout = 6 * time.Second
DieTimeout = 3 * time.Second
KillWait = 3 * time.Second
)

const (
// TODO: find better entries
PlayerShutdownEntry = "[FLog::SingleSurfaceApp] shutDown:"
// Works for both studio and player
ShutdownEntry = "[FLog::Output] Fmod Closed."
)

const (
Expand Down Expand Up @@ -253,7 +253,7 @@ func (b *Binary) Execute(args ...string) error {
// SIGUSR1 is used in Tail() to force kill roblox, used to differenciate between
// a user-sent signal and a self sent signal.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGUSR1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
s := <-c

Expand Down Expand Up @@ -364,13 +364,14 @@ func (b *Binary) Tail(name string) {
for line := range t.Lines {
fmt.Fprintln(b.Prefix.Stderr, line.Text)

// Roblox shut down, give it atleast a few seconds, and then send an
// internal signal to kill it.
// This is due to Roblox occasionally refusing to die. We must kill it.
if strings.Contains(line.Text, PlayerShutdownEntry) {
// Occasionally, Roblox may not close its window and hogs up memory
// as a result.
if strings.Contains(line.Text, ShutdownEntry) {
go func() {
time.Sleep(DieTimeout)
syscall.Kill(syscall.Getpid(), syscall.SIGUSR1)
// Studio takes some time to cleanup its resources.
time.Sleep(KillWait)

syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
}()
}

Expand Down

0 comments on commit 7ebad34

Please sign in to comment.