Browse Source

errcheck: PR comment fixes

pull/703/head
Zach Ramsay 7 years ago
committed by Ethan Buchman
parent
commit
b75d4f73e7
12 changed files with 34 additions and 58 deletions
  1. +1
    -0
      consensus/replay.go
  2. +1
    -0
      consensus/replay_test.go
  3. +0
    -1
      consensus/wal.go
  4. +6
    -4
      mempool/mempool.go
  5. +6
    -25
      p2p/upnp/upnp.go
  6. +4
    -12
      rpc/lib/client/http_client.go
  7. +5
    -5
      rpc/lib/client/ws_client.go
  8. +4
    -5
      rpc/lib/server/handlers.go
  9. +2
    -2
      rpc/lib/server/http_server.go
  10. +2
    -1
      state/execution.go
  11. +1
    -1
      types/part_set.go
  12. +2
    -2
      types/services.go

+ 1
- 0
consensus/replay.go View File

@ -117,6 +117,7 @@ func (cs *ConsensusState) catchupReplay(csHeight int) error {
} else {
defer func() {
if err := gr.Close(); err != nil {
cs.Logger.Error("Error closing wal Search", "err", err)
return
}
}()


+ 1
- 0
consensus/replay_test.go View File

@ -492,6 +492,7 @@ func makeBlockchainFromWAL(wal WAL) ([]*types.Block, []*types.Commit, error) {
}
defer func() {
if err := gr.Close(); err != nil {
wal.Logger.Error("Error closing wal Search", "err", err)
return
}
}()


+ 0
- 1
consensus/wal.go View File

@ -174,7 +174,6 @@ func (wal *baseWAL) SearchForEndHeight(height uint64) (gr *auto.GroupReader, fou
}
}
}
gr.Close()
}


+ 6
- 4
mempool/mempool.go View File

@ -3,6 +3,7 @@ package mempool
import (
"bytes"
"container/list"
"fmt"
"sync"
"sync/atomic"
"time"
@ -191,11 +192,11 @@ func (mem *Mempool) CheckTx(tx types.Tx, cb func(*abci.Response)) (err error) {
// TODO: Notify administrators when WAL fails
_, err := mem.wal.Write([]byte(tx))
if err != nil {
return err
mem.logger.Error(fmt.Sprintf("Error writing to WAL: %v", err))
}
_, err = mem.wal.Write([]byte("\n"))
if err != nil {
return err
mem.logger.Error(fmt.Sprintf("Error writing to WAL: %v", err))
}
}
// END WAL
@ -337,9 +338,9 @@ func (mem *Mempool) collectTxs(maxTxs int) types.Txs {
// Update informs the mempool that the given txs were committed and can be discarded.
// NOTE: this should be called *after* block is committed by consensus.
// NOTE: unsafe; Lock/Unlock must be managed by caller
func (mem *Mempool) Update(height int, txs types.Txs) {
func (mem *Mempool) Update(height int, txs types.Txs) error {
if err := mem.proxyAppConn.FlushSync(); err != nil { // To flush async resCb calls e.g. from CheckTx
panic(err)
return err
}
// First, create a lookup map of txns in new txs.
txsMap := make(map[string]struct{})
@ -363,6 +364,7 @@ func (mem *Mempool) Update(height int, txs types.Txs) {
// mem.recheckCursor re-scans mem.txs and possibly removes some txs.
// Before mem.Reap(), we should wait for mem.recheckCursor to be nil.
}
return nil
}
func (mem *Mempool) filterTxs(blockTxsMap map[string]struct{}) []types.Tx {


+ 6
- 25
p2p/upnp/upnp.go View File

@ -40,11 +40,7 @@ func Discover() (nat NAT, err error) {
return
}
socket := conn.(*net.UDPConn)
defer func() {
if err := socket.Close(); err != nil {
return
}
}()
defer socket.Close()
if err := socket.SetDeadline(time.Now().Add(3 * time.Second)); err != nil {
return nil, err
@ -201,11 +197,8 @@ func getServiceURL(rootURL string) (url, urnDomain string, err error) {
if err != nil {
return
}
defer func() {
if err := r.Body.Close(); err != nil {
return
}
}()
defer r.Body.Close()
if r.StatusCode >= 400 {
err = errors.New(string(r.StatusCode))
return
@ -303,11 +296,7 @@ func (n *upnpNAT) getExternalIPAddress() (info statusInfo, err error) {
var response *http.Response
response, err = soapRequest(n.serviceURL, "GetExternalIPAddress", message, n.urnDomain)
if response != nil {
defer func() {
if err := response.Body.Close(); err != nil {
return
}
}()
defer response.Body.Close()
}
if err != nil {
return
@ -356,11 +345,7 @@ func (n *upnpNAT) AddPortMapping(protocol string, externalPort, internalPort int
var response *http.Response
response, err = soapRequest(n.serviceURL, "AddPortMapping", message, n.urnDomain)
if response != nil {
defer func() {
if err := response.Body.Close(); err != nil {
return
}
}()
defer response.Body.Close()
}
if err != nil {
return
@ -386,11 +371,7 @@ func (n *upnpNAT) DeletePortMapping(protocol string, externalPort, internalPort
var response *http.Response
response, err = soapRequest(n.serviceURL, "DeletePortMapping", message, n.urnDomain)
if response != nil {
defer func() {
if err := response.Body.Close(); err != nil {
return
}
}()
defer response.Body.Close()
}
if err != nil {
return


+ 4
- 12
rpc/lib/client/http_client.go View File

@ -93,12 +93,8 @@ func (c *JSONRPCClient) Call(method string, params map[string]interface{}, resul
if err != nil {
return nil, err
}
defer func() {
if err := httpResponse.Body.Close(); err != nil {
panic(err)
return
}
}()
defer httpResponse.Body.Close()
responseBytes, err := ioutil.ReadAll(httpResponse.Body)
if err != nil {
return nil, err
@ -133,12 +129,8 @@ func (c *URIClient) Call(method string, params map[string]interface{}, result in
if err != nil {
return nil, err
}
defer func() {
if err := resp.Body.Close(); err != nil {
panic(err)
return
}
}()
defer resp.Body.Close()
responseBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err


+ 5
- 5
rpc/lib/client/ws_client.go View File

@ -291,7 +291,7 @@ func (c *WSClient) processBacklog() error {
case request := <-c.backlog:
if c.writeWait > 0 {
if err := c.conn.SetWriteDeadline(time.Now().Add(c.writeWait)); err != nil {
panic(err)
c.Logger.Error("failed to set write deadline", "err", err)
}
}
if err := c.conn.WriteJSON(request); err != nil {
@ -363,7 +363,7 @@ func (c *WSClient) writeRoutine() {
case request := <-c.send:
if c.writeWait > 0 {
if err := c.conn.SetWriteDeadline(time.Now().Add(c.writeWait)); err != nil {
panic(err)
c.Logger.Error("failed to set write deadline", "err", err)
}
}
if err := c.conn.WriteJSON(request); err != nil {
@ -376,7 +376,7 @@ func (c *WSClient) writeRoutine() {
case <-ticker.C:
if c.writeWait > 0 {
if err := c.conn.SetWriteDeadline(time.Now().Add(c.writeWait)); err != nil {
panic(err)
c.Logger.Error("failed to set write deadline", "err", err)
}
}
if err := c.conn.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
@ -392,7 +392,7 @@ func (c *WSClient) writeRoutine() {
return
case <-c.Quit:
if err := c.conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")); err != nil {
panic(err)
c.Logger.Error("failed to write message", "err", err)
}
return
}
@ -424,7 +424,7 @@ func (c *WSClient) readRoutine() {
// reset deadline for every message type (control or data)
if c.readWait > 0 {
if err := c.conn.SetReadDeadline(time.Now().Add(c.readWait)); err != nil {
panic(err)
c.Logger.Error("failed to set read deadline", "err", err)
}
}
_, data, err := c.conn.ReadMessage()


+ 4
- 5
rpc/lib/server/handlers.go View File

@ -534,6 +534,7 @@ func (wsc *wsConnection) readRoutine() {
}
}
}()
defer wsc.baseConn.Close()
wsc.baseConn.SetPongHandler(func(m string) error {
return wsc.baseConn.SetReadDeadline(time.Now().Add(wsc.readWait))
@ -546,7 +547,7 @@ func (wsc *wsConnection) readRoutine() {
default:
// reset deadline for every type of message (control or data)
if err := wsc.baseConn.SetReadDeadline(time.Now().Add(wsc.readWait)); err != nil {
panic(err)
wsc.Logger.Error("failed to set read deadline", "err", err)
}
var in []byte
_, in, err := wsc.baseConn.ReadMessage()
@ -619,9 +620,7 @@ func (wsc *wsConnection) writeRoutine() {
pingTicker := time.NewTicker(wsc.pingPeriod)
defer func() {
pingTicker.Stop()
if err := wsc.baseConn.Close(); err != nil {
panic(err)
}
wsc.baseConn.Close()
}()
// https://github.com/gorilla/websocket/issues/97
@ -781,6 +780,6 @@ func writeListOfEndpoints(w http.ResponseWriter, r *http.Request, funcMap map[st
w.WriteHeader(200)
_, err := w.Write(buf.Bytes())
if err != nil {
panic(err)
// ignore error
}
}

+ 2
- 2
rpc/lib/server/http_server.go View File

@ -58,7 +58,7 @@ func WriteRPCResponseHTTPError(w http.ResponseWriter, httpCode int, res types.RP
w.WriteHeader(httpCode)
_, err = w.Write(jsonBytes)
if err != nil {
panic(err)
// ignore error
}
}
@ -71,7 +71,7 @@ func WriteRPCResponseHTTP(w http.ResponseWriter, res types.RPCResponse) {
w.WriteHeader(200)
_, err = w.Write(jsonBytes)
if err != nil {
panic(err)
// ignore error
}
}


+ 2
- 1
state/execution.go View File

@ -288,10 +288,11 @@ func (s *State) indexTxs(abciResponses *ABCIResponses) {
Tx: tx,
Result: *d,
}); err != nil {
panic(err)
s.logger.Error("Error with batch.Add", "err", err)
}
}
if err := s.TxIndexer.AddBatch(batch); err != nil {
s.logger.Error("Error adding batch", "err", err)
panic(err)
}
}


+ 1
- 1
types/part_set.go View File

@ -36,7 +36,7 @@ func (part *Part) Hash() []byte {
hasher := ripemd160.New()
_, err := hasher.Write(part.Bytes)
if err != nil {
panic(err)
// ignore error
}
part.hash = hasher.Sum(nil)
return part.hash


+ 2
- 2
types/services.go View File

@ -25,7 +25,7 @@ type Mempool interface {
Size() int
CheckTx(Tx, func(*abci.Response)) error
Reap(int) Txs
Update(height int, txs Txs)
Update(height int, txs Txs) error
Flush()
TxsAvailable() <-chan int
@ -42,7 +42,7 @@ func (m MockMempool) Unlock() {}
func (m MockMempool) Size() int { return 0 }
func (m MockMempool) CheckTx(tx Tx, cb func(*abci.Response)) error { return nil }
func (m MockMempool) Reap(n int) Txs { return Txs{} }
func (m MockMempool) Update(height int, txs Txs) {}
func (m MockMempool) Update(height int, txs Txs) error { return nil }
func (m MockMempool) Flush() {}
func (m MockMempool) TxsAvailable() <-chan int { return make(chan int) }
func (m MockMempool) EnableTxsAvailable() {}


Loading…
Cancel
Save