|
1 |
| -import { Logger, logger } from "@coder/logger" |
| 1 | +import { field, Logger, logger } from "@coder/logger" |
2 | 2 | import * as cp from "child_process"
|
3 | 3 | import { promises as fs } from "fs"
|
4 | 4 | import * as path from "path"
|
5 | 5 | import { Page } from "playwright"
|
6 | 6 | import { onLine } from "../../../src/node/util"
|
7 | 7 | import { PASSWORD, workspaceDir } from "../../utils/constants"
|
8 |
| -import { tmpdir } from "../../utils/helpers" |
| 8 | +import { idleTimer, tmpdir } from "../../utils/helpers" |
9 | 9 |
|
10 | 10 | interface CodeServerProcess {
|
11 | 11 | process: cp.ChildProcess
|
@@ -99,34 +99,44 @@ export class CodeServer {
|
99 | 99 | },
|
100 | 100 | )
|
101 | 101 |
|
| 102 | + const timer = idleTimer("Failed to extract address; did the format change?", reject) |
| 103 | + |
102 | 104 | proc.on("error", (error) => {
|
103 | 105 | this.logger.error(error.message)
|
| 106 | + timer.dispose() |
104 | 107 | reject(error)
|
105 | 108 | })
|
106 | 109 |
|
107 |
| - proc.on("close", () => { |
| 110 | + proc.on("close", (code) => { |
108 | 111 | const error = new Error("closed unexpectedly")
|
109 | 112 | if (!this.closed) {
|
110 |
| - this.logger.error(error.message) |
| 113 | + this.logger.error(error.message, field("code", code)) |
111 | 114 | }
|
| 115 | + timer.dispose() |
112 | 116 | reject(error)
|
113 | 117 | })
|
114 | 118 |
|
115 | 119 | let resolved = false
|
116 | 120 | proc.stdout.setEncoding("utf8")
|
117 | 121 | onLine(proc, (line) => {
|
| 122 | + // As long as we are actively getting input reset the timer. If we stop |
| 123 | + // getting input and still have not found the address the timer will |
| 124 | + // reject. |
| 125 | + timer.reset() |
| 126 | + |
118 | 127 | // Log the line without the timestamp.
|
119 | 128 | this.logger.trace(line.replace(/\[.+\]/, ""))
|
120 | 129 | if (resolved) {
|
121 | 130 | return
|
122 | 131 | }
|
123 |
| - const match = line.trim().match(/HTTP server listening on (https?:\/\/[.:\d]+)$/) |
| 132 | + const match = line.trim().match(/HTTP server listening on (https?:\/\/[.:\d]+)\/?$/) |
124 | 133 | if (match) {
|
125 | 134 | // Cookies don't seem to work on IP address so swap to localhost.
|
126 | 135 | // TODO: Investigate whether this is a bug with code-server.
|
127 | 136 | const address = match[1].replace("127.0.0.1", "localhost")
|
128 | 137 | this.logger.debug(`spawned on ${address}`)
|
129 | 138 | resolved = true
|
| 139 | + timer.dispose() |
130 | 140 | resolve({ process: proc, address })
|
131 | 141 | }
|
132 | 142 | })
|
|
0 commit comments