Closed mousedownmike closed 4 years ago
Hi,
Thanks for diving xray sdk. The code seems not safe because there might be race condition that more than one goroutines call xray.AddError(ctx, e)
at the same time. Could you try to replace line _ = xray.AddError(ctx, e)
to add e
into another channel, then raise a new goroutine to poll Err from this channel and call _ = xray.AddError(ctx, e)
? by this way it makes sure no race condition in xray.AddError
Thanks
@wangzlei thanks for the reply. Ok, that makes sense. I don't think I get enough value from the additional error metadata in my X-Ray trace to go through that effort, I can easily extract that data from my logs.
Here's a quick question before I close this issue. Are any of the SDK functions considered safe for concurrent use in Go? I don't see anything in the docs one way or the other.
Sorry that in doc we don't mention too much about sdk's concurrency safety. In goLang world by default we suppose the sdk is not concurrency safety and have to use Channel or lock to handle multi-threads case, unless explicitly say it is concurrency safety.
Thanks @wangzlei
I've been hesitating opening an issue for this because it is so intermittent but it has appeared in both unit test runs and in production runs. The fault occurs at various places in my code but it always stems from calling
xray.AddError(ctx, e)
in a manner similar to:That is being called inside of a
go func()
that is part of a WaitGroup reading records off a channel (I've updated the example to more clearly articulate this). Is it possible there is a concurrency problem with my call to AddError? Should I be doing that in a different way? Note that this code is being run in a Lambda function so it runs inside the Facade segment.This is consistently the trace of the exception.