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
using tusd handler with gorilla mux causing "NetworkControlError" warnings #1100
Comments
Can you provide a minimal example to reproduce this? The code causing this warning uses
Could it be that mux only provides you with a wrapped ResponseWriter and not the original one? What version of HTTP does your requests have? HTTP/1.1, HTTP/2 or HTTP/3 over QUIC? |
hi, i adapted the basic example from the docs using gorilla mux, the warnings can be reproduced when using a middleware function with mux via examplepackage main
import (
"fmt"
"net/http"
"time"
"github.com/gorilla/mux"
"github.com/tus/tusd/v2/pkg/filestore"
tusd "github.com/tus/tusd/v2/pkg/handler"
)
func main() {
store := filestore.FileStore{
Path: "./uploads",
}
composer := tusd.NewStoreComposer()
store.UseIn(composer)
handler, err := tusd.NewHandler(tusd.Config{
BasePath: "/files/",
StoreComposer: composer,
NotifyCompleteUploads: true,
})
if err != nil {
panic(fmt.Errorf("unable to create handler: %s", err))
}
go func() {
for {
event := <-handler.CompleteUploads
fmt.Printf("Upload %s finished\n", event.Upload.ID)
}
}()
r := mux.NewRouter()
// mux middleware causing warnings
r.Use(timeoutMiddleware(15 * time.Second))
r.PathPrefix("/files/").Handler(http.StripPrefix("/files/", handler))
srv := &http.Server{
Handler: r,
Addr: "0.0.0.0:8080",
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
srv.ListenAndServe()
}
// example middleware
func timeoutMiddleware(timeout time.Duration) mux.MiddlewareFunc {
return func(next http.Handler) http.Handler {
return http.TimeoutHandler(next, timeout, "timeout")
}
} yes, i am getting a wrapped responsewriter from the middleware so that seems to cause the issue |
In this case, the wrapped ResponseWriter should either implement an If the the logic for wrapping the ResponseWriter is located in the mux package, you could open an issue in their repository asking if this is possible or whether there are other workarounds. |
adding an thanks for reaching out, i will close this question |
I see, so this seems to be a shortcoming of Go's net/http package. I would recommend to report this to Go itself, so the necessary methods can be added to the TimeoutHandler's wrapped ResponseWriters. |
@lukasrabener Can you share an example of how you implemented the |
sure, it is just returning the original ResponseWriter from my custom one. func (mcrw *myCustomResponseWriter) Unwrap() http.ResponseWriter {
return mcrw.ResponseWriter
} |
@lukasrabener Thank you. I did this exactly the same way, but // ignoreNetworkWarnings is a required no-op because the datadog mux ResponseWriter does not support
// SetWriteDeadline and SetReadDeadline. This middleware ignores the SetWriteDeadline/SetReadDeadline warnings
// Read/Write timeouts are handled by the http.Server ReadTimeout and WriteTimeout config instead
type ignoreNetworkWarnings struct {
http.ResponseWriter
}
func (mw *ignoreNetworkWarnings) SetWriteDeadline(t time.Time) error {
return nil
}
func (mw *ignoreNetworkWarnings) SetReadDeadline(t time.Time) error {
return nil
} And I set these configurations on my server to hopefully replace what // Create a new HTTP server using the mux router as the handler.
srv := &http.Server{
Addr: ":8080",
ReadHeaderTimeout: 10 * time.Second,
Handler: muxTracer,
BaseContext: func(listener net.Listener) context.Context { return mainCtx },
// ReadTimeout handles what SetReadDeadline would normally configure
// Their normal default is 60 seconds, so we'll match that
// https://github.com/tus/tusd/blob/15f05c021c9770dc0cd2818aa4ef44b9e361f5b2/pkg/handler/config.go#L97
ReadTimeout: 60 * time.Second,
// WriteTimeout handles what SetWriteDeadline would normally configure
// Their normal default is 120 seconds, so we'll match that
// https://github.com/tus/tusd/blob/15f05c021c9770dc0cd2818aa4ef44b9e361f5b2/pkg/handler/unrouted_handler.go#L181
WriteTimeout: 120 * time.Second,
} |
Question
How to properly configure tusd handler to be used by gorilla mux without causing warnings of tusd middleware setting Read & Write Deadlines.
Setup details
Please provide following details, if applicable to your situation:
when integrating the handler.NewHandler() into my existing gorilla mux with:
i get alot of warnings for every request as the tusd middleware is trying to set Read & Write Deadlines which seems not supported:
SetReadDeadline
The text was updated successfully, but these errors were encountered: