Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak #1197

Merged
merged 2 commits into from Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -263,10 +263,10 @@ private[monix] object TaskBracket {
}

private final def makeUncancelable(task: Task[B]): Task[B] = {
// NOTE: the "restore" part of this is `null` because we don't need to restore
// the original connection. The original connection gets restored automatically
// via how "TaskRestartCallback" works. This is risky!
ContextSwitch(task, withConnectionUncancelable, null)
// Unregistering cancel token, otherwise we can have a memory leak;
// N.B. conn.pop() happens after the evaluation of `release`, because
// otherwise we might have a conflict with the auto-cancellation logic
ContextSwitch(task, withConnectionUncancelable, disableUncancelableAndPop)
}
}

Expand All @@ -282,4 +282,10 @@ private[monix] object TaskBracket {

private[this] val withConnectionUncancelable: Context => Context =
_.withConnection(TaskConnection.uncancelable)

private[this] val disableUncancelableAndPop: (Any, Throwable, Context, Context) => Context =
(_, _, old, _) => {
old.connection.pop()
old
}
}
Expand Up @@ -56,7 +56,7 @@ private[eval] sealed abstract class TaskConnection extends CancelableF[Task] {

/**
* Pushes a cancelable token on the stack, to be
* popped or canceled later in FIFO order.
* popped or canceled later in LIFO order.
*
* The function needs a [[monix.execution.Scheduler Scheduler]]
* to work because in case the connection was already cancelled,
Expand All @@ -66,7 +66,7 @@ private[eval] sealed abstract class TaskConnection extends CancelableF[Task] {

/**
* Pushes a [[monix.execution.Cancelable]] on the stack, to be
* popped or canceled later in FIFO order.
* popped or canceled later in LIFO order.
*
* The function needs a [[monix.execution.Scheduler Scheduler]]
* to work because in case the connection was already cancelled,
Expand All @@ -76,7 +76,7 @@ private[eval] sealed abstract class TaskConnection extends CancelableF[Task] {

/**
* Pushes a [[monix.catnap.CancelableF]] on the stack, to be
* popped or canceled later in FIFO order.
* popped or canceled later in LIFO order.
*
* The function needs a [[monix.execution.Scheduler Scheduler]]
* to work because in case the connection was already cancelled,
Expand All @@ -94,7 +94,7 @@ private[eval] sealed abstract class TaskConnection extends CancelableF[Task] {
def pushConnections(seq: CancelableF[Task]*)(implicit s: Scheduler): Unit

/**
* Removes a cancelable reference from the stack in FIFO order.
* Removes a cancelable reference from the stack in LIFO order.
*
* @return the cancelable reference that was removed.
*/
Expand Down