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

[price-feeder] gracefully handle nil response for new provider #617

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions oracle/price-feeder/oracle/provider/binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ func NewBinanceProvider(
}

wsConn, response, err := websocket.DefaultDialer.Dial(wsURL.String(), nil)
defer response.Body.Close()
defer func() {
if response != nil {
response.Body.Close()
}
}()
if err != nil {
return nil, fmt.Errorf("error connecting to Binance websocket: %w", err)
}
Expand Down Expand Up @@ -366,7 +370,11 @@ func (p *BinanceProvider) reconnect() error {

p.logger.Debug().Msg("reconnecting websocket")
wsConn, response, err := websocket.DefaultDialer.Dial(p.wsURL.String(), nil)
defer response.Body.Close()
defer func() {
if response != nil {
response.Body.Close()
}
}()
if err != nil {
return fmt.Errorf("error reconnect to binance websocket: %w", err)
}
Expand Down
12 changes: 10 additions & 2 deletions oracle/price-feeder/oracle/provider/coinbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ func NewCoinbaseProvider(
}

wsConn, response, err := websocket.DefaultDialer.Dial(wsURL.String(), nil)
defer response.Body.Close()
defer func() {
if response != nil {
response.Body.Close()
}
}()
if err != nil {
return nil, fmt.Errorf("error connecting to Coinbase websocket: %w", err)
}
Expand Down Expand Up @@ -486,7 +490,11 @@ func (p *CoinbaseProvider) reconnect() error {

p.logger.Debug().Msg("reconnecting websocket")
wsConn, response, err := websocket.DefaultDialer.Dial(p.wsURL.String(), nil)
defer response.Body.Close()
defer func() {
if response != nil {
response.Body.Close()
}
}()
if err != nil {
return fmt.Errorf("error reconnecting to Coinbase websocket: %w", err)
}
Expand Down
12 changes: 10 additions & 2 deletions oracle/price-feeder/oracle/provider/gate.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ func NewGateProvider(
}

wsConn, response, err := websocket.DefaultDialer.Dial(wsURL.String(), nil)
defer response.Body.Close()
defer func() {
if response != nil {
response.Body.Close()
}
}()
if err != nil {
return nil, fmt.Errorf("error connecting to Gate websocket: %w", err)
}
Expand Down Expand Up @@ -551,7 +555,11 @@ func (p *GateProvider) reconnect() error {

p.logger.Debug().Msg("reconnecting websocket")
wsConn, response, err := websocket.DefaultDialer.Dial(p.wsURL.String(), nil)
defer response.Body.Close()
defer func() {
if response != nil {
response.Body.Close()
}
}()
if err != nil {
return fmt.Errorf("error reconnecting to Gate websocket: %w", err)
}
Expand Down
12 changes: 10 additions & 2 deletions oracle/price-feeder/oracle/provider/huobi.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ func NewHuobiProvider(
}

wsConn, response, err := websocket.DefaultDialer.Dial(wsURL.String(), nil)
defer response.Body.Close()
defer func() {
if response != nil {
response.Body.Close()
}
}()
if err != nil {
return nil, fmt.Errorf("error connecting to Huobi websocket: %w", err)
}
Expand Down Expand Up @@ -388,7 +392,11 @@ func (p *HuobiProvider) reconnect() error {

p.logger.Debug().Msg("reconnecting websocket")
wsConn, response, err := websocket.DefaultDialer.Dial(p.wsURL.String(), nil)
defer response.Body.Close()
defer func() {
if response != nil {
response.Body.Close()
}
}()
if err != nil {
return fmt.Errorf("error reconnecting to Huobi websocket: %w", err)
}
Expand Down
12 changes: 10 additions & 2 deletions oracle/price-feeder/oracle/provider/kraken.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ func NewKrakenProvider(
}

wsConn, response, err := websocket.DefaultDialer.Dial(wsURL.String(), nil)
defer response.Body.Close()
defer func() {
if response != nil {
response.Body.Close()
}
}()
if err != nil {
return nil, fmt.Errorf("error connecting to websocket: %w", err)
}
Expand Down Expand Up @@ -492,7 +496,11 @@ func (p *KrakenProvider) reconnect() error {
p.logger.Debug().Msg("trying to reconnect")

wsConn, response, err := websocket.DefaultDialer.Dial(p.wsURL.String(), nil)
defer response.Body.Close()
defer func() {
if response != nil {
response.Body.Close()
}
}()
if err != nil {
return fmt.Errorf("error connecting to Kraken websocket: %w", err)
}
Expand Down
12 changes: 10 additions & 2 deletions oracle/price-feeder/oracle/provider/mexc.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ func NewMexcProvider(
}

wsConn, response, err := websocket.DefaultDialer.Dial(wsURL.String(), nil)
defer response.Body.Close()
defer func() {
if response != nil {
response.Body.Close()
}
}()
if err != nil {
return nil, fmt.Errorf("error connecting to mexc websocket: %w", err)
}
Expand Down Expand Up @@ -396,7 +400,11 @@ func (p *MexcProvider) reconnect() error {

p.logger.Debug().Msg("mexc: reconnecting websocket")
wsConn, response, err := websocket.DefaultDialer.Dial(p.wsURL.String(), nil)
defer response.Body.Close()
defer func() {
if response != nil {
response.Body.Close()
}
}()
if err != nil {
return fmt.Errorf("mexc: error reconnect to mexc websocket: %w", err)
}
Expand Down
12 changes: 10 additions & 2 deletions oracle/price-feeder/oracle/provider/okx.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ func NewOkxProvider(
}

wsConn, response, err := websocket.DefaultDialer.Dial(wsURL.String(), nil)
defer response.Body.Close()
defer func() {
if response != nil {
response.Body.Close()
}
}()
if err != nil {
return nil, fmt.Errorf("error connecting to Okx websocket: %w", err)
}
Expand Down Expand Up @@ -430,7 +434,11 @@ func (p *OkxProvider) reconnect() error {

p.logger.Debug().Msg("reconnecting websocket")
wsConn, response, err := websocket.DefaultDialer.Dial(p.wsURL.String(), nil)
defer response.Body.Close()
defer func() {
if response != nil {
response.Body.Close()
}
}()
if err != nil {
return fmt.Errorf("error reconnecting to Okx websocket: %w", err)
}
Expand Down