Skip to content
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

SSE Error with gin adapter: "warning: unable to set write deadline" #491

Open
darrenparkinson opened this issue Jun 28, 2024 · 5 comments
Open
Labels
question Further information is requested

Comments

@darrenparkinson
Copy link

Hi,

Just looking to add SSE to an existing project that uses the gin router.

I'm using the example here but when I swap the router for Gin, I'm getting the error: warning: unable to set write deadline for every sent message.

e.g.

router := gin.Default()
api := humagin.New(router, huma.DefaultConfig("My API", "1.0.0"))

I notice this doesn't happen when using humago or humachi.

I can see that the error comes from this line here I think, but not sure what I'd need to do to fix that?

Is it because the gin context referenced in the adapter doesn't implement the SetWriteDeadline(time.Time) error function?

Any thoughts greatly appreciated.
Many thanks.

@danielgtaylor danielgtaylor added the question Further information is requested label Aug 1, 2024
@danielgtaylor
Copy link
Owner

@darrenparkinson it seems that the Gin context's Writer field doesn't support it. Maybe there is a different way to do SSE with Gin? Here is an example that seems to use built-in functionality in Gin:

https://github.com/gin-gonic/examples/blob/master/server-sent-event/main.go#L65

You may just not be able to use this functionality in Huma with Gin as the router. The alternative would be to try and figure out how to build it into the Gin adapter, but I'm not sure how feasible that is.

@clausMeko
Copy link

clausMeko commented Aug 24, 2024

@danielgtaylor I had the same problem and just switched to a different sse implementation.

It uses http.Handler and no huma.Operation.

Problem: Is there a way to get an entry in the openAPi doc say for api/v1/stream ?

cheers

@clausMeko
Copy link

clausMeko commented Aug 24, 2024

I am a little confused why this works:

noOp := func(context.Context, *struct{}) (*struct{}, error) {
  return nil, nil
}
huma.Get(api, "/shelf/stream", noOp, tag("stream"))
r.Handle("/shelf/stream", s)

where s is the alternative implementation.

I thought if a handler is registered for a route it there cannot be another one. But it works and i leave it for documentation, so one can get some OpenApi entries for http.Handler.
This might also kind of fixes #486. I guess they could put noops for old endpoints and incrementally upgrade to huma.

@jzillmann
Copy link

getting the same logging with chi...

@clausMeko
Copy link

@jzillmann I have to confirm that, was also using chi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants