Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ npx expo run:android

Shell input and resize requests share one ordered queue. Shutdown stops accepting
new input immediately, and remote closure stops the writer. A closed channel
returns `ChannelClosed`; transport failures and writes through a closed or
unbound Android terminal are reported through `onClosed` with an error message.
returns `ChannelClosed`; a write through an unbound terminal is reported through
`onClosed`. A transport reports `onClosed` exactly once: later writes are dropped
silently and a failing resize adds no further event, until a new source is bound.

The SSH integration tests run only when `SSH_TEST_HOST` is set. The
`shell_preserves_rapid_single_byte_writes` test sends 16,384 individual writes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ class ReactNativeSshTerminalView(context: Context, appContext: AppContext) : Exp

override fun onClosed(exitStatus: Int?, error: String?) {
mainHandler.post {
if (!transportClosed) {
transportClosed = true
session.notifyTransportClosed(exitStatus ?: 0, error)
}
// One transport closes once: the notice and the event are skipped for
// every later close report, and a rebound source starts a new cycle.
if (transportClosed) return@post
transportClosed = true
session.notifyTransportClosed(exitStatus ?: 0, error)
TerminalViewEvents.emit(this@ReactNativeSshTerminalView, "onClosed", Bundle().apply {
putInt("exitStatus", exitStatus ?: 0)
putString("error", error)
Expand All @@ -59,10 +60,9 @@ class ReactNativeSshTerminalView(context: Context, appContext: AppContext) : Exp

private val transport = object : TerminalTransport {
override fun write(data: ByteArray, offset: Int, count: Int) {
if (transportClosed) {
sink.onClosed(null, "terminal source is closed")
return
}
// A closed transport stays closed until a new source is bound: later writes
// are dropped here, because the close notice and event already went out.
if (transportClosed) return
val target = source
if (target == null) {
sink.onClosed(null, "terminal source '${sourceId.orEmpty()}' is not bound")
Expand Down
10 changes: 6 additions & 4 deletions ios/Terminal/ReactNativeSshTerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ public final class ReactNativeSshTerminalView: ExpoView, TerminalViewDelegate, T
}

private func write(_ bytes: Data) {
// A closed transport stays closed until a new source is bound: later writes
// are dropped here, because the close notice and event already went out.
if transportClosed {
closeTransport(exitStatus: nil, error: "terminal source is closed")
return
}
guard let source else {
Expand All @@ -258,10 +259,11 @@ public final class ReactNativeSshTerminalView: ExpoView, TerminalViewDelegate, T
}

private func closeTransport(exitStatus: Int?, error: String?) {
if !transportClosed {
transportClosed = true
feedCloseNotice(exitStatus: exitStatus, error: error)
guard !transportClosed else {
return
}
transportClosed = true
feedCloseNotice(exitStatus: exitStatus, error: error)
let errorValue: Any = error.map { $0 as Any } ?? NSNull()
onClosed(["exitStatus": exitStatus ?? 0, "error": errorValue])
}
Expand Down
Loading