Connections now can only trigger as expired from when they are created, not when they are last valid. Changed from images.isConnected -> images.count
This commit is contained in:
parent
e5bcd3cb1a
commit
93a892f439
|
@ -474,17 +474,11 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
|
|||
// If the connection has either been closed, or has expired, it needs to be cleaned-up/deleted.
|
||||
var shouldCleanupConnection = false
|
||||
|
||||
if (newConnection.isExpired()) {
|
||||
logger.debug {"[${newConnection.id}] connection expired"}
|
||||
shouldCleanupConnection = true
|
||||
}
|
||||
|
||||
else if (newConnection.isClosed()) {
|
||||
if (newConnection.isClosed()) {
|
||||
logger.debug {"[${newConnection.id}] connection closed"}
|
||||
shouldCleanupConnection = true
|
||||
}
|
||||
|
||||
|
||||
if (shouldCleanupConnection) {
|
||||
close()
|
||||
return@launch
|
||||
|
|
|
@ -485,17 +485,11 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
|||
// If the connection has either been closed, or has expired, it needs to be cleaned-up/deleted.
|
||||
var shouldCleanupConnection = false
|
||||
|
||||
if (connection.isExpired()) {
|
||||
logger.trace {"[${connection.id}] connection expired"}
|
||||
shouldCleanupConnection = true
|
||||
}
|
||||
|
||||
else if (connection.isClosed()) {
|
||||
if (connection.isClosed()) {
|
||||
logger.trace {"[${connection.id}] connection closed"}
|
||||
shouldCleanupConnection = true
|
||||
}
|
||||
|
||||
|
||||
if (shouldCleanupConnection) {
|
||||
// remove this connection so there won't be an attempt to poll it again
|
||||
true
|
||||
|
|
|
@ -98,7 +98,7 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
|
|||
internal var postCloseAction: suspend () -> Unit = {}
|
||||
|
||||
// only accessed on a single thread!
|
||||
private var previousConnectionStartTime = Long.MAX_VALUE
|
||||
private val connectionInitTime = System.nanoTime()
|
||||
|
||||
private val isClosed = atomic(false)
|
||||
|
||||
|
@ -291,25 +291,17 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
|
|||
return messagesInProgress.value
|
||||
}
|
||||
|
||||
/**
|
||||
* @return `true` if this connection has no subscribers (which means this connection does not have a remote connection)
|
||||
*/
|
||||
internal fun isExpired(): Boolean {
|
||||
return if (subscription.isConnected) {
|
||||
previousConnectionStartTime = System.nanoTime()
|
||||
false
|
||||
}
|
||||
else {
|
||||
// images can be in a state of flux. Sometimes they come and go VERY quickly
|
||||
System.nanoTime() - previousConnectionStartTime >= TimeUnit.SECONDS.toNanos(endPoint.config.connectionCloseTimeoutInSeconds.toLong())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return `true` if this connection has been closed
|
||||
*/
|
||||
fun isClosed(): Boolean {
|
||||
return isClosed.value
|
||||
val hasNoImages = subscription.hasNoImages()
|
||||
if (hasNoImages) {
|
||||
// 1) connections take a little bit of time from polling -> connecting (because of how we poll connections before 'connecting' them).
|
||||
return System.nanoTime() - connectionInitTime >= TimeUnit.SECONDS.toNanos(1)
|
||||
}
|
||||
|
||||
return hasNoImages
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user