-
-
Notifications
You must be signed in to change notification settings - Fork 165
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
fiber sigsev #686
Comments
So locally with fiber I get this after a while and instantly with prefork true. |
@badsgahhl thanks for reporting. My guess is that it must be related to the changes in #659. I don't personally use fiber so any help would be appreciated. @excavador any ideas on this one? |
I will take a look closer tomorrow and fix it |
@badsgahhl @danielgtaylor I am sorry for delay. I am looking now. |
I understand the issue, but I need to rethink how to fix it. fasthttp has a precise way of handling fasthttp.RequestCtx and I make implementation incompatible with it. It sounds like you are using Context.Err() after exit from the HTTP handler, and that is the reason why you catch this issue. I will rethink how to adjust my version to avoid a crash like this on one hands, and race conditions with fasthttp on other hands |
@danielgtaylor BTW, refer to So, we have issue already, even before my fix.
I will rework adapter there to avoid this bug and any similar issues. Just keep you informed about my discoveries |
…uestCtx outside handler, fixes danielgtaylor#686
@badsgahhl could you please try to use code from my Pull Request and confirm that issue is fixes? |
Tried it and got the panic
|
…uestCtx outside handler, fixes danielgtaylor#686
@badsgahhl perfect! What does it mean: you try to use "huma.Context" or "Context()" from huma.Context OUTSIDE handler. According to documentation of Fiber and FastHttp server it is prohibited Take a look to this link https://docs.gofiber.io/#zero-allocation Other words: this is EXPECTED behavior |
@badsgahhl if you show me your code, I could explain where the problem with it and how to change it |
We actually don't use anything beyond the handler. And also I still only get the error reproductible while using Fiber Preforking. |
Unless I missunderstand something important, your stacktrace is evidence that you are actually try to use it outside handler! Please, take a look to your stack trace.
Inside stack trace I could see "humafiber.go:51" and "humafiber.go:70", but I can not see something like "humafiber.go:207" What it is important?
Our point to interest the ling number 203-208
We do not have any of it inside stacktrace! What does it mean?
|
CC @badsgahhl ^ |
Just from looking at the handlers I don't see anything that would use the context more than it should be used. All huma handlers pass down the context to the database etc. just as normal. The only thing that really always causes crashes now is if huma requests and fiber request are sent in parallel while preforking is active. So to explain: The application currently transitions to huma handlers but uses huma handlers and legacy fiber handlers in parallel. If a page calls both of them in parallel (e.g. react-query tab switch) and preforking is enabled then the application crashes. Otherwise I really don't see any issues there. Otherwise we should have noticed some weird behavior some versions before in my opinion. |
@badsgahhl I took a closer look to implementation of golang Context and this is mind-blowing - lines 509-512
Sounds like cancelation of the parent context try to use children context, and context.Cause call I am rethinking your stack-trace and try to wrap my head about this really weird consequences to figure out proper fix. I will let you know when I figure it out |
@badsgahhl could you please try updated version of my PR? |
Works 👍🏼 with the small test case I have. Will try it out some time. Just some sidenote:
As you mentioned this causes the error: child.cancel(false, parent.Err(), Cause(parent)) Is it really correct to return nil here for the &cancelCtxKey. Just saw that line during debugging. No clue if this could break something up tbh. |
@badsgahhl thank you for letting me know! In general, this is the big surprise to me, how context.Context is working actually! In our application - https://docs.truvity.com/ - we are heavily use context.Value, and there is the reason of the original patch from my side. The performance-related behavior of fiber and fasthttp + separation to "Context" and "UserContext" inside fasthttp make the proper implementation of "Context" inside adapter extremely complicated! Please let me know, if you will find any other issues, I will be glad to fix my code @danielgtaylor I think the PR is good to go |
@badsgahhl if it was the question
then correct, because "parent" context where is my context from adapter, and it propagate cancel to children context. In my case it will be the usual normal "Cancel" without any "Cause", and because of that returing nil is okay - it will pick up "Cause" from chilren context, not from the my context from adapter Unless I missunderstood something important :) |
We updated one of our apps to 2.27 from 2.26 and now get a SIGSEGV. We cant really reproduce this behavior locally but we use prefork true in the staging env this app is currently running.
The text was updated successfully, but these errors were encountered: