~egtann/srp

b28e623a984b7627b6b97e3e1219b035a189f34d — Evan Tann a month ago 0ede4d4 master
fix deadlock on peristent http requests
1 files changed, 5 insertions(+), 3 deletions(-)

M proxy.go
M proxy.go => proxy.go +5 -3
@@ 138,12 138,14 @@ func NewProxy(log Logger, reg *Registry, timeout time.Duration) *ReverseProxy {
}

func (r *ReverseProxy) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	r.mu.RLock()
	defer r.mu.RUnlock()

	// Handle redirects before proxying. Non-existent host errors will be
	// handled by the reverse proxy, so we don't need to handle them here.
	// We want to unlock this as quickly as possible, not just after the
	// request is done for cases like websockets where the request stays
	// open indefinitely.
	r.mu.RLock()
	host, ok := r.reg.Services[req.Host]
	r.mu.RUnlock()
	if ok && host.Redirect != nil {
		doRedirect(w, req, host.Redirect)
		return