pgserve 0.1.4 → 0.1.5
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/package.json +1 -1
- package/src/protocol.js +18 -4
package/package.json
CHANGED
package/src/protocol.js
CHANGED
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
const PROTOCOL_VERSION_3 = 196608;
|
|
14
|
-
const SSL_REQUEST_CODE = 80877103;
|
|
14
|
+
const SSL_REQUEST_CODE = 80877103; // PostgreSQL SSL negotiation request
|
|
15
|
+
const GSSAPI_REQUEST_CODE = 80877104; // PostgreSQL GSSAPI encryption request
|
|
16
|
+
const CANCEL_REQUEST_CODE = 80877102; // PostgreSQL cancel request
|
|
15
17
|
const DATABASE_KEY = Buffer.from('database\0');
|
|
16
18
|
|
|
17
19
|
/**
|
|
@@ -179,14 +181,14 @@ export async function readStartupMessage(socket) {
|
|
|
179
181
|
// Resume socket AFTER listeners are set up (prevents race condition)
|
|
180
182
|
socket.resume();
|
|
181
183
|
|
|
182
|
-
// Timeout after
|
|
184
|
+
// Timeout after 2 seconds (reduced from 5s for faster probe connection handling)
|
|
183
185
|
setTimeout(() => {
|
|
184
186
|
if (resolved) return;
|
|
185
187
|
resolved = true;
|
|
186
188
|
socket.removeListener('data', onData);
|
|
187
189
|
socket.removeListener('error', onError);
|
|
188
190
|
reject(new Error('Timeout reading startup message'));
|
|
189
|
-
},
|
|
191
|
+
}, 2000);
|
|
190
192
|
});
|
|
191
193
|
}
|
|
192
194
|
|
|
@@ -199,7 +201,7 @@ export async function readStartupMessage(socket) {
|
|
|
199
201
|
export async function extractDatabaseNameFromSocket(socket) {
|
|
200
202
|
let { message, allData } = await readStartupMessage(socket);
|
|
201
203
|
|
|
202
|
-
// Check if this is
|
|
204
|
+
// Check if this is a protocol negotiation request (SSL, GSSAPI, Cancel)
|
|
203
205
|
if (message.length >= 8) {
|
|
204
206
|
const version = message.readInt32BE(4);
|
|
205
207
|
|
|
@@ -211,6 +213,18 @@ export async function extractDatabaseNameFromSocket(socket) {
|
|
|
211
213
|
const result = await readStartupMessage(socket);
|
|
212
214
|
message = result.message;
|
|
213
215
|
allData = result.allData;
|
|
216
|
+
} else if (version === GSSAPI_REQUEST_CODE) {
|
|
217
|
+
// Respond with 'N' (no GSSAPI support)
|
|
218
|
+
socket.write(Buffer.from('N'));
|
|
219
|
+
|
|
220
|
+
// Read the actual startup message
|
|
221
|
+
const result = await readStartupMessage(socket);
|
|
222
|
+
message = result.message;
|
|
223
|
+
allData = result.allData;
|
|
224
|
+
} else if (version === CANCEL_REQUEST_CODE) {
|
|
225
|
+
// Cancel request - PGlite doesn't support query cancellation
|
|
226
|
+
// Just close gracefully (cancel requests don't expect a response)
|
|
227
|
+
throw new Error('Cancel request received (not supported)');
|
|
214
228
|
}
|
|
215
229
|
}
|
|
216
230
|
|