Skip to content

Commit

Permalink
close reader in all case (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoqin-li1123 authored and nlu90 committed Feb 1, 2024
1 parent 958250e commit 946c36c
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private[pulsar] abstract class PulsarSourceRDDBase(
.loadConf(readerConf)
.create()

new NextIterator[InternalRow] {
val iter = new NextIterator[InternalRow] {

private var inEnd: Boolean = false
private var isLast: Boolean = false
Expand Down Expand Up @@ -150,7 +150,6 @@ private[pulsar] abstract class PulsarSourceRDDBase(
} catch {
case e: PulsarClientException =>
logError(s"PulsarClient failed to read message from topic $topic", e)
close()
throw e
case e: Throwable =>
throw e
Expand All @@ -161,6 +160,10 @@ private[pulsar] abstract class PulsarSourceRDDBase(
reader.close()
}
}
context.addTaskCompletionListener[Unit] { _ =>
iter.closeIfNeeded()
}
iter
}
}

Expand Down

0 comments on commit 946c36c

Please sign in to comment.