diff --git a/.gitignore b/.gitignore index 6821a0d..fd5e168 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ nix/nginx/logs/nginx.pid *.control *.so nginx.pid +tags diff --git a/docs/contributing.md b/docs/contributing.md index 408d5ec..45030d7 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -56,6 +56,24 @@ select net.http_get('http://localhost:3000/projects'); -- * Connection #0 to host localhost left intact ``` +### GDB + +To debug the background worker, grab its PID from the logs: + +``` +$ nix-shell +$ net-with-pg-16 psql + +2024-09-02 20:16:26.905 -05 [1145879] INFO: pg_net_worker started with a config of: pg_net.ttl=6 hours, pg_net.batch_size=200, pg_net.database_name=postgres +``` + +And use it like: + +``` +$ nix-shell +$ sudo with-gdb -p 1145879 +``` + ## Documentation All public API must be documented. Building documentation requires python 3.6+ diff --git a/nix/gdbScript.nix b/nix/gdbScript.nix new file mode 100644 index 0000000..f994c66 --- /dev/null +++ b/nix/gdbScript.nix @@ -0,0 +1,12 @@ +{ gdb, writeText, writeShellScriptBin } : + +let + file = writeText "gdbconf" '' + # Do this so we can do `backtrace` once a segfault occurs. Otherwise once SIGSEGV is received the bgworker will quit and we can't backtrace. + handle SIGSEGV stop nopass + ''; + script = '' + ${gdb}/bin/gdb -x ${file} "$@" + ''; +in +writeShellScriptBin "with-gdb" script diff --git a/nix/pgScript.nix b/nix/pgScript.nix index 40b9b2d..8181830 100644 --- a/nix/pgScript.nix +++ b/nix/pgScript.nix @@ -2,7 +2,7 @@ let LOGMIN = builtins.getEnv "LOGMIN"; - logMin = if builtins.stringLength LOGMIN == 0 then "WARNING" else LOGMIN; # warning is the default in pg + logMin = if builtins.stringLength LOGMIN == 0 then "INFO" else LOGMIN; ver = builtins.head (builtins.splitVersion postgresql.version); script = '' set -euo pipefail diff --git a/nix/pg_net.nix b/nix/pg_net.nix index 905828e..cceb62a 100644 --- a/nix/pg_net.nix +++ b/nix/pg_net.nix @@ -7,6 +7,9 @@ stdenv.mkDerivation { src = ../.; + # this is enough for enabling debug info + dontStrip = true; + installPhase = '' mkdir -p $out/bin install -D pg_net.so -t $out/lib diff --git a/shell.nix b/shell.nix index 3b1523a..0733e99 100644 --- a/shell.nix +++ b/shell.nix @@ -24,6 +24,7 @@ mkShell { extAll = map (x: callPackage ./nix/pgScript.nix { postgresql = pgWithExt { pg = x;}; }) supportedPgVersions; nginxScript = callPackage ./nix/nginxScript.nix {}; pathodScript = callPackage ./nix/pathodScript.nix { mitmproxy = oldNixpkgs.mitmproxy; }; + gdbScript = callPackage ./nix/gdbScript.nix {}; pythonDeps = with python3Packages; [ pytest psycopg2 @@ -37,6 +38,7 @@ mkShell { format.do format.doCheck nginxScript pathodScript + gdbScript ]; shellHook = '' export HISTFILE=.history