@@ -37,6 +37,7 @@ const (
3737 supervisorHomeEnv = "SGREP_RERANKER_SUPERVISOR_HOME"
3838 supervisorPortEnv = "SGREP_RERANKER_SUPERVISOR_PORT"
3939 supervisorLifecycleEnv = "SGREP_RERANKER_SUPERVISOR_LIFECYCLE_LOCK"
40+ supervisorRunnerDebugEnv = "SGREP_RERANKER_SUPERVISOR_RUNNER_GODEBUG"
4041 supervisorProtocolVersion = 1
4142 guardianCleanShutdown = byte (0x73 )
4243 guardianReady = byte (0x61 )
@@ -320,7 +321,7 @@ func runConstrainedReranker(args []string) error {
320321 if command [0 ] != runnerContinue {
321322 return fmt .Errorf ("invalid constrained reranker authorization" )
322323 }
323- environment := withoutSupervisorEnvironment (os .Environ ())
324+ environment := environmentForConstrainedReranker (os .Environ ())
324325 if err := syscall .Exec (executable , commandArgs , environment ); err != nil {
325326 return fmt .Errorf ("exec constrained reranker: %w" , err )
326327 }
@@ -1318,12 +1319,52 @@ func environmentForGuardian(environment []string) []string {
13181319
13191320func environmentForRunner (environment []string , instance string ) []string {
13201321 result := environmentForReranker (environment , instance )
1322+ filtered := result [:0 ]
1323+ runnerDebug := "asyncpreemptoff=1"
1324+ for _ , entry := range result {
1325+ if strings .HasPrefix (entry , "GODEBUG=" ) {
1326+ original := strings .TrimPrefix (entry , "GODEBUG=" )
1327+ filtered = append (filtered , supervisorRunnerDebugEnv + "=" + original )
1328+ if original != "" {
1329+ runnerDebug = original + "," + runnerDebug
1330+ }
1331+ continue
1332+ }
1333+ filtered = append (filtered , entry )
1334+ }
1335+ // Darwin's PT_TRACE_ME can delay an asynchronous preemption signal forever,
1336+ // deadlocking runtime_BeforeExec. The setting is removed before the target
1337+ // exec, so it applies only to the short-lived Go runner.
1338+ result = append (filtered , "GODEBUG=" + runnerDebug )
13211339 return append (result ,
13221340 supervisorModeEnv + "=1" ,
13231341 supervisorProtocolEnv + "=" + strconv .Itoa (supervisorProtocolVersion ),
13241342 )
13251343}
13261344
1345+ func environmentForConstrainedReranker (environment []string ) []string {
1346+ var originalDebug string
1347+ var restoreDebug bool
1348+ debugPrefix := supervisorRunnerDebugEnv + "="
1349+ for _ , entry := range environment {
1350+ if strings .HasPrefix (entry , debugPrefix ) {
1351+ originalDebug = strings .TrimPrefix (entry , debugPrefix )
1352+ restoreDebug = true
1353+ }
1354+ }
1355+ result := withoutSupervisorEnvironment (environment )
1356+ filtered := result [:0 ]
1357+ for _ , entry := range result {
1358+ if ! strings .HasPrefix (entry , "GODEBUG=" ) {
1359+ filtered = append (filtered , entry )
1360+ }
1361+ }
1362+ if restoreDebug {
1363+ filtered = append (filtered , "GODEBUG=" + originalDebug )
1364+ }
1365+ return filtered
1366+ }
1367+
13271368func environmentForReranker (environment []string , instance string ) []string {
13281369 result := withoutSupervisorEnvironment (environment )
13291370 prefix := rerankerInstanceEnv + "="
0 commit comments