diff --git a/server.conf.in b/server.conf.in index 09e44ab2..05c1cbb1 100644 --- a/server.conf.in +++ b/server.conf.in @@ -116,6 +116,9 @@ connectionsperhost = 8 # Default is 2 mbit/sec. #maxscreenbitrate = 2097152 +# For type "proxy": timeout in seconds for requests to the proxy server. +#proxytimeout = 2 + # For type "proxy": type of URL configuration for proxy servers. # Defaults to "static". # diff --git a/src/signaling/mcu_proxy.go b/src/signaling/mcu_proxy.go index d1085196..9cd4b5c2 100644 --- a/src/signaling/mcu_proxy.go +++ b/src/signaling/mcu_proxy.go @@ -63,6 +63,8 @@ const ( initialWaitDelay = time.Second maxWaitDelay = 8 * time.Second + + defaultProxyTimeoutSeconds = 2 ) type mcuProxyPubSubCommon struct { @@ -912,6 +914,7 @@ type mcuProxy struct { connectionsMu sync.RWMutex connRequests int64 nextSort int64 + proxyTimeout time.Duration mu sync.RWMutex publishers map[string]*mcuProxyConnection @@ -940,11 +943,19 @@ func NewMcuProxy(config *goconf.ConfigFile) (Mcu, error) { return nil, fmt.Errorf("Could not parse private key from %s: %s", tokenKeyFilename, err) } + proxyTimeoutSeconds, _ := config.GetInt("mcu", "proxytimeout") + if proxyTimeoutSeconds <= 0 { + proxyTimeoutSeconds = defaultProxyTimeoutSeconds + } + proxyTimeout := time.Duration(proxyTimeoutSeconds) * time.Second + log.Printf("Using a timeout of %s for proxy requests", proxyTimeout) + mcu := &mcuProxy{ tokenId: tokenId, tokenKey: tokenKey, connectionsMap: make(map[string]*mcuProxyConnection), + proxyTimeout: proxyTimeout, publishers: make(map[string]*mcuProxyConnection), @@ -1490,7 +1501,9 @@ func (m *mcuProxy) NewPublisher(ctx context.Context, listener McuListener, id st continue } - publisher, err := conn.newPublisher(ctx, listener, id, streamType) + subctx, cancel := context.WithTimeout(ctx, m.proxyTimeout) + defer cancel() + publisher, err := conn.newPublisher(subctx, listener, id, streamType) if err != nil { log.Printf("Could not create %s publisher for %s on %s: %s", streamType, id, conn.url, err) continue