Skip to content

Commit 685b9d9

Browse files
authored
add timeout to abi request (#209)
### TL;DR Added HTTP timeout for ABI fetching operations to prevent hanging requests. ### What changed? - Added a 10-second timeout to the HTTP client used for fetching contract ABIs - Imported the `time` package to support the timeout functionality - Replaced the direct `http.Get()` call with a custom client that has timeout configuration ### How to test? 1. Verify that ABI fetching operations complete or fail within 10 seconds 2. Test with a slow or unresponsive API endpoint to confirm the timeout works correctly 3. Ensure existing ABI fetching functionality continues to work normally with responsive endpoints ### Why make this change? Without a timeout, HTTP requests to fetch contract ABIs could potentially hang indefinitely if the API endpoint is unresponsive, causing resource leaks and degraded performance. This change ensures that requests will fail gracefully after 10 seconds, allowing the system to handle errors appropriately and maintain responsiveness. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved reliability of contract ABI fetching by adding a timeout to prevent requests from hanging indefinitely. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 77ebcc3 + fb460a4 commit 685b9d9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

internal/common/abi.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"regexp"
77
"strings"
88
"sync"
9+
"time"
910

1011
config "github.com/thirdweb-dev/indexer/configs"
1112

@@ -34,7 +35,12 @@ func GetABIForContractWithCache(chainId string, contract string, abiCache map[st
3435
func GetABIForContract(chainId string, contract string) (*abi.ABI, error) {
3536
url := fmt.Sprintf("%s/abi/%s/%s", config.Cfg.API.ThirdwebContractApi, chainId, contract)
3637

37-
resp, err := http.Get(url)
38+
// Create a custom client with timeouts
39+
client := &http.Client{
40+
Timeout: 10 * time.Second,
41+
}
42+
43+
resp, err := client.Get(url)
3844
if err != nil {
3945
return nil, fmt.Errorf("failed to get contract abi: %v", err)
4046
}

0 commit comments

Comments
 (0)