Skip to content

cmd/derper: add support for running the stun responder as a subprocess - #10745

Closed
raggi wants to merge 1 commit into
mainfrom
raggi/stun-subprocess
Closed

raggi wants to merge 1 commit into
mainfrom
raggi/stun-subprocess

Conversation

@raggi

@raggi raggi commented Jan 5, 2024

Copy link
Copy Markdown
Member

If a derper is loaded for any reason, it can add spurious additional runtime to stun responses producing latency estimation errors in the clients. For some deployment scenarios simply running the stun responder as a subprocess is a simple solution to substantially reduce this problem.

@raggi
raggi requested a review from jwhited January 5, 2024 02:39
@raggi
raggi force-pushed the raggi/stun-subprocess branch from b794cb4 to 1be4ed7 Compare January 5, 2024 03:56
If a derper is loaded for any reason, it can add spurious additional
runtime to stun responses producing latency estimation errors in the
clients. For some deployment scenarios simply running the stun responder
as a subprocess is a simple solution to substantially reduce this
problem.

Fixes #8434
Closes #8435

Signed-off-by: James Tucker <[email protected]>
@raggi
raggi force-pushed the raggi/stun-subprocess branch from 1be4ed7 to c6aeb67 Compare January 5, 2024 03:57
@bradfitz

bradfitz commented Jan 5, 2024

Copy link
Copy Markdown
Member

For some deployment scenarios

We going to nice the processes separately, or what?

Comment thread cmd/derper/stun.go
log.Fatalf("stun: failed to start subprocess: %v", err)
}
readSTUNStats(ctx, stdout)
cmd.Process.Kill()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth noting that this sends a SIGKILL; maybe worth allowing things to gracefully shut down with a SIGTERM and then waiting and killing with SIGKILL?

	cmd.Process.Signal(syscall.SIGTERM)
	killed := make(chan struct{})
	go func() {
		select {
		case <-killed:
		case <-time.After(2*time.Second):
			cmd.Process.Kill()
		}
	}()
	cmd.Process.Wait()
	close(killed)

@raggi raggi Jan 5, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kill is probably superfluous anyway - if the read has stopped it's more than likely the pipe is closed, which most commonly means the process is gone. I just didn't want to have wait hang indefinitely on some edge case.

Comment thread cmd/derper/stun.go
log.Fatalf("failed to open STUN listener: %v", err)
}
log.Printf("running STUN server on %v", pc.LocalAddr())
// close the listener on shutdown in order to rbeak out of the read loop

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// close the listener on shutdown in order to rbeak out of the read loop
// close the listener on shutdown in order to break out of the read loop

Comment thread cmd/derper/derper.go
if *stunOnly {
log.SetPrefix(fmt.Sprintf("stun(%d) ", os.Getpid()))
log.Printf("Starting in stun-only mode.")
go printSTUNStats(ctx, os.Stdout, time.Second*10)

@knyar knyar Jan 5, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I suggest to consider having the subprocess expose its own debug http server? This will improve our ability to introspect it via pprof, and will allow adding it separately to Prometheus. This will give us a bunch of built-in Go runtime metrics for free (gc metrics, goroutine count, memstats, cpu time) and help avoid bespoke metric serializaton machinery.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That change ends up being a lot bigger once it is rationalized, because the basic take on process supervision and argument delegation taken here no longer makes so much sense. At that point we may as well split out a stund entirely, and manage it separately - but doing so then also requires new deployment machinery as well. I understand the motivations you're describing, it just may block us addressing this issue again, which has already been stuck for months due to time-cost trade-offs - e.g. see the PR that this supersedes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's fixit-friday so I did it anyway: #10757

@raggi

raggi commented Jan 5, 2024

Copy link
Copy Markdown
Member Author

We going to nice the processes separately, or what?

I wasn't planning to, the kernel scheduler should perform fine here.

raggi added a commit that referenced this pull request Jan 5, 2024
Add a standalone server for STUN that can be hosted independently of the
derper, and factor that back into the derper.

Fixes #8434
Closes #8435
Closes #10745

Signed-off-by: James Tucker <[email protected]>
@raggi

raggi commented Jan 5, 2024

Copy link
Copy Markdown
Member Author

This patch is superseded by #10757 which splits this out into an entirely standalone service.

@raggi raggi closed this Jan 5, 2024
raggi added a commit that referenced this pull request Jan 8, 2024
Add a standalone server for STUN that can be hosted independently of the
derper, and factor that back into the derper.

Fixes #8434
Closes #8435
Closes #10745

Signed-off-by: James Tucker <[email protected]>
raggi added a commit that referenced this pull request Jan 8, 2024
Add a standalone server for STUN that can be hosted independently of the
derper, and factor that back into the derper.

Fixes #8434
Closes #8435
Closes #10745

Signed-off-by: James Tucker <[email protected]>
raggi added a commit that referenced this pull request Jan 8, 2024
Add a standalone server for STUN that can be hosted independently of the
derper, and factor that back into the derper.

Fixes #8434
Closes #8435
Closes #10745

Signed-off-by: James Tucker <[email protected]>
raggi added a commit that referenced this pull request Jan 8, 2024
Add a standalone server for STUN that can be hosted independently of the
derper, and factor that back into the derper.

Fixes #8434
Closes #8435
Closes #10745

Signed-off-by: James Tucker <[email protected]>
raggi added a commit that referenced this pull request Jan 8, 2024
Add a standalone server for STUN that can be hosted independently of the
derper, and factor that back into the derper.

Fixes #8434
Closes #8435
Closes #10745

Signed-off-by: James Tucker <[email protected]>
raggi added a commit that referenced this pull request Jan 8, 2024
Add a standalone server for STUN that can be hosted independently of the
derper, and factor that back into the derper.

Fixes #8434
Closes #8435
Closes #10745

Signed-off-by: James Tucker <[email protected]>
raggi added a commit that referenced this pull request Jan 8, 2024
Add a standalone server for STUN that can be hosted independently of the
derper, and factor that back into the derper.

Fixes #8434
Closes #8435
Closes #10745

Signed-off-by: James Tucker <[email protected]>
raggi added a commit that referenced this pull request Jan 9, 2024
Add a standalone server for STUN that can be hosted independently of the
derper, and factor that back into the derper.

Fixes #8434
Closes #8435
Closes #10745

Signed-off-by: James Tucker <[email protected]>
kari-ts pushed a commit that referenced this pull request Jan 12, 2024
Add a standalone server for STUN that can be hosted independently of the
derper, and factor that back into the derper.

Fixes #8434
Closes #8435
Closes #10745

Signed-off-by: James Tucker <[email protected]>
Asutorufa pushed a commit to Asutorufa/tailscale that referenced this pull request Jan 19, 2024
Add a standalone server for STUN that can be hosted independently of the
derper, and factor that back into the derper.

Fixes tailscale#8434
Closes tailscale#8435
Closes tailscale#10745

Signed-off-by: James Tucker <[email protected]>
chen8945 pushed a commit to Ckid-Home/tailscale that referenced this pull request Jul 31, 2024
Add a standalone server for STUN that can be hosted independently of the
derper, and factor that back into the derper.

Fixes tailscale#8434
Closes tailscale#8435
Closes tailscale#10745

Signed-off-by: James Tucker <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants