Implement connection timeout (#4081)

This commit is contained in:
Chris Stewart 2022-02-12 09:11:13 -06:00 committed by GitHub
parent 526ed37a28
commit 55ecc1ae8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,6 +10,7 @@ import org.bitcoins.tor.{Socks5Connection, Socks5ProxyParams}
import java.io.IOException
import java.net.InetSocketAddress
import scala.concurrent.duration.DurationInt
import scala.concurrent.{Future, Promise}
class DLCClient(
@ -36,7 +37,14 @@ class DLCClient(
remoteAddress
}
context.become(connecting(peer))
IO(Tcp) ! Tcp.Connect(peerOrProxyAddress)
//currently our request timeout for requests sent to the backend is 60 seconds
//so we need the connection timeout to occur before the request times out
//when a user tries to submit an accept to the backend
//see: https://github.com/bitcoin-s/bitcoin-s/issues/4080
val connectionTimeout = 45.seconds
IO(Tcp) ! Tcp.Connect(peerOrProxyAddress,
timeout = Some(connectionTimeout))
}
def connecting(peer: Peer): Receive = LoggingReceive {
@ -44,7 +52,6 @@ class DLCClient(
val ex = c.cause.getOrElse(new IOException("Unknown Error"))
log.error(s"Cannot connect to ${cmd.remoteAddress} ", ex)
throw ex
case Tcp.Connected(peerOrProxyAddress, _) =>
val connection = sender()
peer.socks5ProxyParams match {