@@ -195,9 +195,7 @@ func WithValue(ctx DBOSContext, key, val any) DBOSContext {
195195 // Will do nothing if the concrete type is not dbosContext
196196 if dbosCtx , ok := ctx .(* dbosContext ); ok {
197197 launched := dbosCtx .launched .Load ()
198- childCtxLaunched := atomic.Bool {}
199- childCtxLaunched .Store (launched )
200- return & dbosContext {
198+ childCtx := & dbosContext {
201199 ctx : context .WithValue (dbosCtx .ctx , key , val ), // Spawn a new child context with the value set
202200 logger : dbosCtx .logger ,
203201 systemDB : dbosCtx .systemDB ,
@@ -207,8 +205,9 @@ func WithValue(ctx DBOSContext, key, val any) DBOSContext {
207205 applicationVersion : dbosCtx .applicationVersion ,
208206 executorID : dbosCtx .executorID ,
209207 applicationID : dbosCtx .applicationID ,
210- launched : childCtxLaunched ,
211208 }
209+ childCtx .launched .Store (launched )
210+ return childCtx
212211 }
213212 return nil
214213}
@@ -222,11 +221,9 @@ func WithoutCancel(ctx DBOSContext) DBOSContext {
222221 }
223222 if dbosCtx , ok := ctx .(* dbosContext ); ok {
224223 launched := dbosCtx .launched .Load ()
225- childCtxLaunched := atomic.Bool {}
226- childCtxLaunched .Store (launched )
227224 // Create a new context that is not canceled when the parent is canceled
228225 // but retains all other values
229- return & dbosContext {
226+ childCtx := & dbosContext {
230227 ctx : context .WithoutCancel (dbosCtx .ctx ),
231228 logger : dbosCtx .logger ,
232229 systemDB : dbosCtx .systemDB ,
@@ -236,8 +233,9 @@ func WithoutCancel(ctx DBOSContext) DBOSContext {
236233 applicationVersion : dbosCtx .applicationVersion ,
237234 executorID : dbosCtx .executorID ,
238235 applicationID : dbosCtx .applicationID ,
239- launched : childCtxLaunched ,
240236 }
237+ childCtx .launched .Store (launched )
238+ return childCtx
241239 }
242240 return nil
243241}
@@ -251,10 +249,8 @@ func WithTimeout(ctx DBOSContext, timeout time.Duration) (DBOSContext, context.C
251249 }
252250 if dbosCtx , ok := ctx .(* dbosContext ); ok {
253251 launched := dbosCtx .launched .Load ()
254- childCtxLaunched := atomic.Bool {}
255- childCtxLaunched .Store (launched )
256252 newCtx , cancelFunc := context .WithTimeoutCause (dbosCtx .ctx , timeout , errors .New ("DBOS context timeout" ))
257- return & dbosContext {
253+ childCtx := & dbosContext {
258254 ctx : newCtx ,
259255 logger : dbosCtx .logger ,
260256 systemDB : dbosCtx .systemDB ,
@@ -264,8 +260,9 @@ func WithTimeout(ctx DBOSContext, timeout time.Duration) (DBOSContext, context.C
264260 applicationVersion : dbosCtx .applicationVersion ,
265261 executorID : dbosCtx .executorID ,
266262 applicationID : dbosCtx .applicationID ,
267- launched : childCtxLaunched ,
268- }, cancelFunc
263+ }
264+ childCtx .launched .Store (launched )
265+ return childCtx , cancelFunc
269266 }
270267 return nil , func () {}
271268}
0 commit comments