Skip to content

Commit

Permalink
tun2socks: panic at random api for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Jan 23, 2025
1 parent 2942835 commit 422473c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions intra/dnsx/cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ func (t *ctransport) hangoverCheckpoint() {

func (t *ctransport) fetch(network string, q *dns.Msg, summary *x.DNSSummary, cb *cache, key string) (*dns.Msg, error) {
sendRequest := func(fsmm *x.DNSSummary) (*dns.Msg, error) {
if false && settings.Debug && rand10pc() {
panic("test crash")
if settings.PanicAtRandom.Load() && rand10pc() {
panic("dns: cache: fetch: rand10pc")
}

fsmm.QName = summary.QName
Expand Down
2 changes: 1 addition & 1 deletion intra/netstack/forwarders.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (p *processor) deliverPackets() {
pkt.DecRef()
}
p.mu.Lock()
if false && settings.Debug && rand10pc() {
if settings.PanicAtRandom.Load() && rand10pc() {
panic("ns: tun: forwarder: deliverPackets rand10pc")
}
}
Expand Down
4 changes: 4 additions & 0 deletions intra/settings/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ var SystemDNSForUndelegatedDomains = atomic.Bool{}
// to "Intra".
var SetUserAgentForDoH = atomic.Bool{}

// PanicAtRandom is a global flag to panic the network engine
// every once in a while (for testing).
var PanicAtRandom = atomic.Bool{}

// L3 returns the string'd repr of engine.
func L3(engine int) string {
switch engine {
Expand Down
7 changes: 7 additions & 0 deletions intra/tun2socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ func PrintStack(onConsole bool) {
}
}

// PanicAtRandom instruct portions under test of the network engine
// to panic at random.
func PanicAtRandom(y bool) {
settings.PanicAtRandom.Store(y)
log.I("tun: panic at random? %t", y)
}

// SetCrashFd sets output file to go runtime crashes to.
func SetCrashFd(fp string) (ok bool) {
defer func() {
Expand Down

1 comment on commit 422473c

@ignoramous
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please sign in to comment.