Skip to content

Commit

Permalink
Use dedicated (shorter) timeout for proxy requests.
Browse files Browse the repository at this point in the history
This will prevent the overall MCU timeout to expire on the first proxy
request if that takes too long. With the shorter proxy timeout, the other
proxy servers will be retried if the first request timed out.
  • Loading branch information
fancycode committed Sep 16, 2020
1 parent 612b1d7 commit 7e3a7af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions server.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -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".
#
Expand Down
15 changes: 14 additions & 1 deletion src/signaling/mcu_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const (

initialWaitDelay = time.Second
maxWaitDelay = 8 * time.Second

defaultProxyTimeoutSeconds = 2
)

type mcuProxyPubSubCommon struct {
Expand Down Expand Up @@ -912,6 +914,7 @@ type mcuProxy struct {
connectionsMu sync.RWMutex
connRequests int64
nextSort int64
proxyTimeout time.Duration

mu sync.RWMutex
publishers map[string]*mcuProxyConnection
Expand Down Expand Up @@ -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),

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7e3a7af

Please sign in to comment.