MCPcopy Create free account
hub / github.com/PostHog/duckgres / CreateSession

Method CreateSession

controlplane/worker_mgr.go:1268–1320  ·  view source on GitHub ↗

CreateSession creates a new session on the given worker. secretStatements are the user's persistent secrets to replay on the worker before the session serves queries; secretWarnings reports any that failed to apply.

(ctx context.Context, username, memoryLimit string, threads int, secretStatements []string)

Source from the content-addressed store, hash-verified

1266 // process restarts, including one from a fresh
1267 // session on this (reusable) worker.
1268 mu.Lock()
1269 delete(failures, w.ID)
1270 mu.Unlock()
1271
1272 workerInstanceInvalidatedTotal.Inc()
1273 slog.Error("Worker DuckDB instance invalidated by a fatal engine error; retiring worker.",
1274 "id", w.ID, "reason", hcResult.InstanceInvalidReason)
1275
1276 p.mu.Lock()
1277 _, stillInPool := p.workers[w.ID]
1278 if stillInPool {
1279 delete(p.workers, w.ID)
1280 }
1281 workerCount := len(p.workers)
1282 p.mu.Unlock()
1283 observeControlPlaneWorkers(workerCount)
1284
1285 if stillInPool {
1286 if onCrash != nil {
1287 onCrash(w.ID)
1288 }
1289 if w.cmd.Process != nil {
1290 _ = w.cmd.Process.Kill()
1291 }
1292 <-w.done
1293 if w.client != nil {
1294 _ = w.client.Close()
1295 }
1296 p.releaseWorkerSocket(w)
1297 }
1298 } else {
1299 mu.Lock()
1300 delete(failures, w.ID)
1301 mu.Unlock()
1302
1303 // Forward progress data to the control plane.
1304 if onProgress != nil && hcResult != nil {
1305 if sp := hcResult.toSessionProgress(); len(sp) > 0 {
1306 onProgress(w.ID, sp)
1307 }
1308 }
1309 }
1310 }
1311 }(w)
1312 }
1313 wg.Wait()
1314 }
1315 }
1316}
1317
1318// recoverWorkerPanic converts a nil-pointer panic from a closed Flight SQL
1319// client into an error. Same race as FlightExecutor: arrow-go Close() nils out
1320// FlightServiceClient, and concurrent DoAction calls on the shared client panic.
1321func recoverWorkerPanic(err *error) {
1322 if r := recover(); r != nil {
1323 if re, ok := r.(runtime.Error); ok && strings.Contains(re.Error(), "nil pointer") {

Callers

nothing calls this directly

Calls 6

OwnerEpochMethod · 0.95
OwnerCPInstanceIDMethod · 0.95
recoverWorkerPanicFunction · 0.85
DoActionMethod · 0.45
RecvMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected