Browse Source

Pass http.ServeTLS() errors back to the caller (#2461)

Closes: #2460

* Pass http.ServeTLS() errors back to the caller
* Update CHANGELOG
* Amend StartHTTPServer() too for consistency's sake
* Revert "Amend StartHTTPServer() too for consistency's sake"
This reverts commit 23bfb4c2e9.
pull/2466/merge
Alessio Treglia 6 years ago
committed by Alexander Simmerl
parent
commit
f11db8c1b0
3 changed files with 25 additions and 8 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +9
    -8
      rpc/lib/server/http_server.go
  3. +15
    -0
      rpc/lib/server/http_server_test.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -33,3 +33,4 @@ IMPROVEMENTS:
BUG FIXES:
- [node] \#2294 Delay starting node until Genesis time
- [rpc] \#2460 StartHTTPAndTLSServer() now passes StartTLS() errors back to the caller rather than hanging forever.

+ 9
- 8
rpc/lib/server/http_server.go View File

@ -102,15 +102,16 @@ func StartHTTPAndTLSServer(
listener = netutil.LimitListener(listener, config.MaxOpenConnections)
}
go func() {
err := http.ServeTLS(
listener,
RecoverAndLogHandler(maxBytesHandler{h: handler, n: maxBodyBytes}, logger),
certFile,
keyFile,
)
err = http.ServeTLS(
listener,
RecoverAndLogHandler(maxBytesHandler{h: handler, n: maxBodyBytes}, logger),
certFile,
keyFile,
)
if err != nil {
logger.Error("RPC HTTPS server stopped", "err", err)
}()
return nil, err
}
return listener, nil
}


+ 15
- 0
rpc/lib/server/http_server_test.go View File

@ -5,11 +5,14 @@ import (
"io"
"io/ioutil"
"net/http"
"os"
"sync"
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
)
@ -60,3 +63,15 @@ func TestMaxOpenConnections(t *testing.T) {
t.Errorf("%d requests failed within %d attempts", failed, attempts)
}
}
func TestStartHTTPAndTLSServer(t *testing.T) {
// set up fixtures
listenerAddr := "tcp://0.0.0.0:0"
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {})
// test failure
gotListener, err := StartHTTPAndTLSServer(listenerAddr, mux, "", "", log.TestingLogger(), Config{MaxOpenConnections: 1})
require.Nil(t, gotListener)
require.IsType(t, (*os.PathError)(nil), err)
}

Loading…
Cancel
Save