-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: middleware panics on ended transaction #1295
base: main
Are you sure you want to change the base?
fix: middleware panics on ended transaction #1295
Conversation
💚 CLA has been signed |
❕ Build Aborted
Expand to view the summary
Build stats
Steps errorsExpand to view the steps failures
|
@eugene-trifonov thanks for opening the PR! What is the use case for ending the transaction in the handler, and not in the middleware? It's expected that the middleware ends the transaction. |
@axw I found it in case when http connection is patched to be websocket connection. And as a result such transaction longs too much time (hours). |
@eugene-trifonov thanks for the info.
Do you still want to capture the transaction created in the middleware, or would it be an option to not create a transaction in the first place for that route? If that is an option, you could use https://pkg.go.dev/go.elastic.co/apm/module/apmechov4/v2#WithRequestIgnorer to not create these transactions. Then you can create transactions manually in your websocket handler. |
@axw Yeah, I could, actually I've tried already, but such solution has some duplications I would want to have. I have chosen second option, because I was thinking it's not cool that middleware can panic and have memory leak (on |
Won't that
Yes it adds flexibility, but it's also adding a bit of complexity and sets a precedent for other middleware - hence why I'm a bit wary of the change. I don't think it's unreasonable for code to panic if used in a way that is not intended. I understand it doesn't work for your use case so let's try and explore different options. Would you be able to share a small program which exhibits the problem? Ideally with the logging you're expecting as well. |
When transaction is ended already, apmechov4 middleware panics, because
tx.Result
istx.TransactionData.Result
, andTransactionData == nil
when transaction is ended.This commit fixes the problem.