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.
|
// If the connection has either been closed, or has expired, it needs to be cleaned-up/deleted.
|
||||||
var shouldCleanupConnection = false
|
var shouldCleanupConnection = false
|
||||||
|
|
||||||
if (newConnection.isExpired()) {
|
if (newConnection.isClosed()) {
|
||||||
logger.debug {"[${newConnection.id}] connection expired"}
|
|
||||||
shouldCleanupConnection = true
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (newConnection.isClosed()) {
|
|
||||||
logger.debug {"[${newConnection.id}] connection closed"}
|
logger.debug {"[${newConnection.id}] connection closed"}
|
||||||
shouldCleanupConnection = true
|
shouldCleanupConnection = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (shouldCleanupConnection) {
|
if (shouldCleanupConnection) {
|
||||||
close()
|
close()
|
||||||
return@launch
|
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.
|
// If the connection has either been closed, or has expired, it needs to be cleaned-up/deleted.
|
||||||
var shouldCleanupConnection = false
|
var shouldCleanupConnection = false
|
||||||
|
|
||||||
if (connection.isExpired()) {
|
if (connection.isClosed()) {
|
||||||
logger.trace {"[${connection.id}] connection expired"}
|
|
||||||
shouldCleanupConnection = true
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (connection.isClosed()) {
|
|
||||||
logger.trace {"[${connection.id}] connection closed"}
|
logger.trace {"[${connection.id}] connection closed"}
|
||||||
shouldCleanupConnection = true
|
shouldCleanupConnection = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (shouldCleanupConnection) {
|
if (shouldCleanupConnection) {
|
||||||
// remove this connection so there won't be an attempt to poll it again
|
// remove this connection so there won't be an attempt to poll it again
|
||||||
true
|
true
|
||||||
|
|
|
@ -98,7 +98,7 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
|
||||||
internal var postCloseAction: suspend () -> Unit = {}
|
internal var postCloseAction: suspend () -> Unit = {}
|
||||||
|
|
||||||
// only accessed on a single thread!
|
// only accessed on a single thread!
|
||||||
private var previousConnectionStartTime = Long.MAX_VALUE
|
private val connectionInitTime = System.nanoTime()
|
||||||
|
|
||||||
private val isClosed = atomic(false)
|
private val isClosed = atomic(false)
|
||||||
|
|
||||||
|
@ -291,25 +291,17 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
|
||||||
return messagesInProgress.value
|
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
|
* @return `true` if this connection has been closed
|
||||||
*/
|
*/
|
||||||
fun isClosed(): Boolean {
|
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