Connections can linger a bit before becoming expired (underlying aeron streams can quickly come and go)
This commit is contained in:
parent
ae168de114
commit
679e002785
|
@ -94,6 +94,9 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
|
|||
internal var preCloseAction: suspend () -> Unit = {}
|
||||
internal var postCloseAction: suspend () -> Unit = {}
|
||||
|
||||
// only accessed on a single thread!
|
||||
private var previousConnectionStartTime = Long.MAX_VALUE
|
||||
|
||||
private val isClosed = atomic(false)
|
||||
|
||||
/**
|
||||
|
@ -281,33 +284,17 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
|
|||
return messagesInProgress.value
|
||||
}
|
||||
|
||||
|
||||
var previousConnectionExpireTime = Long.MAX_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
|
||||
val now = System.nanoTime()
|
||||
when {
|
||||
previousConnectionExpireTime == Long.MAX_VALUE -> {
|
||||
// this means we haven't set an expire time yet.
|
||||
val timeOut = TimeUnit.SECONDS.toNanos(endPoint.config.connectionCloseTimeoutInSeconds.toLong())
|
||||
previousConnectionExpireTime = now + timeOut
|
||||
false
|
||||
}
|
||||
now < previousConnectionExpireTime -> {
|
||||
false
|
||||
}
|
||||
else -> {
|
||||
true
|
||||
}
|
||||
}
|
||||
System.nanoTime() - previousConnectionStartTime >= TimeUnit.SECONDS.toNanos(endPoint.config.connectionCloseTimeoutInSeconds.toLong())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -344,7 +331,7 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
|
|||
}
|
||||
|
||||
// on close, we want to make sure this file is DELETED!
|
||||
val logFile = endPoint.mediaDriverContext!!.aeronDirectory().resolve("publications").resolve("${publication.registrationId()}.logbuffer")
|
||||
val logFile = endPoint.mediaDriverContext.aeronDirectory().resolve("publications").resolve("${publication.registrationId()}.logbuffer")
|
||||
|
||||
publication.close()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user