dsh-remote 0.8.66 → 0.8.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/exec-job.js CHANGED
@@ -111,6 +111,13 @@ export function startExecJob(registry, { pool, command, label, owner, jobDeadlin
111
111
  abort = ac
112
112
  const done = (async () => {
113
113
  let res
114
+ // Whether the backend actually streamed anything through the tap. A
115
+ // backend without an onData implementation (openssh before issue #80)
116
+ // leaves the ring EMPTY even though the command produced output — the
117
+ // only copy then lives in the return value below, which the callers of
118
+ // a job never see. Flush that copy into the ring at settle time, but
119
+ // ONLY when nothing streamed, or every line would arrive twice.
120
+ let sawStream = false
114
121
  try {
115
122
  res = await pool.exec(command, {
116
123
  // 0/undefined ⇒ no transport deadline: the job outlives the call.
@@ -124,12 +131,19 @@ export function startExecJob(registry, { pool, command, label, owner, jobDeadlin
124
131
  onData: (channel, chunk) => {
125
132
  const text = Buffer.isBuffer(chunk) ? chunk.toString('utf8') : String(chunk)
126
133
  if (!text) return
134
+ sawStream = true
127
135
  try { job.append(text, { channel }) } catch { /* settled: ring closed */ }
128
136
  },
129
137
  })
130
138
  } catch (err) {
131
139
  return { status: 'failed', detail: String((err && err.message) || err) }
132
140
  }
141
+ if (!sawStream) {
142
+ try {
143
+ if (res.stdout) job.append(String(res.stdout), { channel: 'stdout' })
144
+ if (res.stderr) job.append(String(res.stderr), { channel: 'stderr' })
145
+ } catch { /* settled: ring closed */ }
146
+ }
133
147
  if (res.signal === 'ABORTED' || cancelled) return { status: 'killed', detail: cancelled || 'cancelled' }
134
148
  if (res.signal === 'TIMEOUT') return { status: 'killed', detail: `timed out after ${jobDeadlineMs}ms` }
135
149
  const code = res.code