feat: enhance WebRTC port allocation with existing allocation checks and increase upload timeout

This commit is contained in:
anonpenguin23 2026-02-22 11:39:59 +02:00
parent f1dc3014fc
commit 3e9ef5ac6c
4 changed files with 26 additions and 1 deletions

View File

@ -1054,8 +1054,14 @@ func (g *Gateway) handleNamespaceGatewayRequest(w http.ResponseWriter, r *http.R
proxyReq.Header.Set(HeaderInternalAuthNamespace, validatedNamespace)
}
// Use a longer timeout for upload paths (IPFS add can be slow for large files)
proxyTimeout := 30 * time.Second
if strings.HasPrefix(r.URL.Path, "/v1/storage/upload") || strings.HasPrefix(r.URL.Path, "/v1/storage/pin") {
proxyTimeout = 300 * time.Second
}
// Execute proxy request using shared transport for connection pooling
httpClient := &http.Client{Timeout: 30 * time.Second, Transport: g.proxyTransport}
httpClient := &http.Client{Timeout: proxyTimeout, Transport: g.proxyTransport}
resp, err := httpClient.Do(proxyReq)
if err != nil {
cb.RecordFailure()

View File

@ -331,6 +331,7 @@ func (cm *ClusterManager) getClusterNodesWithIPs(ctx context.Context, clusterID
FROM namespace_cluster_nodes ncn
JOIN dns_nodes dn ON ncn.node_id = dn.id
WHERE ncn.namespace_cluster_id = ?
GROUP BY ncn.node_id
`
if err := cm.db.Query(internalCtx, &rows, query, clusterID); err != nil {
return nil, err

View File

@ -49,6 +49,13 @@ func (wpa *WebRTCPortAllocator) AllocateSFUPorts(ctx context.Context, nodeID, na
retryDelay := 100 * time.Millisecond
for attempt := 0; attempt < maxRetries; attempt++ {
// Re-check for existing allocation (handles read-after-write lag on retries)
if attempt > 0 {
if existing, err := wpa.GetSFUPorts(ctx, namespaceClusterID, nodeID); err == nil && existing != nil {
return existing, nil
}
}
block, err := wpa.tryAllocateSFUPorts(internalCtx, nodeID, namespaceClusterID)
if err == nil {
wpa.logger.Info("SFU ports allocated",
@ -148,6 +155,13 @@ func (wpa *WebRTCPortAllocator) AllocateTURNPorts(ctx context.Context, nodeID, n
retryDelay := 100 * time.Millisecond
for attempt := 0; attempt < maxRetries; attempt++ {
// Re-check for existing allocation (handles read-after-write lag on retries)
if attempt > 0 {
if existing, err := wpa.GetTURNPorts(ctx, namespaceClusterID, nodeID); err == nil && existing != nil {
return existing, nil
}
}
block, err := wpa.tryAllocateTURNPorts(internalCtx, nodeID, namespaceClusterID)
if err == nil {
wpa.logger.Info("TURN ports allocated",

View File

@ -75,6 +75,10 @@ resolve_nodes "$@" | while IFS='|' read -r user host pass; do
echo "[$i/$node_count] $user@$host"
upgrade_node "$user" "$host" "$pass"
echo " ✓ Done"
if [ "$i" -lt "$node_count" ]; then
echo " Waiting 30s before next node..."
sleep 30
fi
echo ""
done