Skip to content

Commit

Permalink
rely on net.Dial to test if the supplier is reachable
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyzags committed Feb 16, 2025
1 parent b3fcfd2 commit 49d4a9d
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions pkg/relayer/proxy/synchronous.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/tls"
"fmt"
"io"
"net"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -100,21 +101,15 @@ func (sync *synchronousRPCServer) Stop(ctx context.Context) error {
// Ping tries to dial the suppliers backend URLs to test the connection.
func (sync *synchronousRPCServer) Ping(ctx context.Context) error {
for _, supplierCfg := range sync.serverConfig.SupplierConfigsMap {
httpClient := &http.Client{Timeout: 2 * time.Second}
timeoutDuration := 2 * time.Second
endpointURL := supplierCfg.ServiceConfig.BackendUrl.String()

resp, err := httpClient.Head(endpointURL)
conn, err := net.DialTimeout("tcp", endpointURL, timeoutDuration)
if err != nil {
return err
}
_ = resp.Body.Close()

// DEV_NOTE: Return ANY HTTP error.
if resp.StatusCode >= http.StatusInternalServerError {
return ErrRelayerProxySupplierNotReachable.Wrapf(
"endpoint URL %q; status code: %d",
supplierCfg.ServiceConfig.BackendUrl.String(), resp.StatusCode)
return ErrRelayerProxySupplierNotReachable.
Wrapf("dial timeout: %v", err)
}
conn.Close()
}

return nil
Expand Down

0 comments on commit 49d4a9d

Please sign in to comment.