Skip to content

Instantly share code, notes, and snippets.

@hut8
Last active January 20, 2022 06:09
Show Gist options
  • Save hut8/e38655e1b442ca76a706420498264eef to your computer and use it in GitHub Desktop.
Save hut8/e38655e1b442ca76a706420498264eef to your computer and use it in GitHub Desktop.

Postmortem debugger session for libpq crash

Commit 092b785fad

Microsoft (R) Windows Debugger Version 10.0.22473.1005 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.

*** wait with pending attach

************* Path validation summary **************
Response                         Time (ms)     Location
Deferred                                       srv*
OK                                             C:\Users\dcbow\pg-14.1\libpq
OK                                             C:\Program Files\PostgreSQL\14\debug_symbols
Symbol search path is: srv*;C:\Users\dcbow\pg-14.1\libpq;C:\Program Files\PostgreSQL\14\debug_symbols
Executable search path is: 
ModLoad: 00007ff7`421c0000 00007ff7`42e7f000   C:\Users\dcbow\Documents\Code\todo\todo-app\target\debug\todo-app.exe
ModLoad: 00007ff8`ef010000 00007ff8`ef205000   C:\WINDOWS\SYSTEM32\ntdll.dll
ModLoad: 00007ff8`ee340000 00007ff8`ee3fe000   C:\WINDOWS\System32\KERNEL32.DLL
ModLoad: 00007ff8`ec720000 00007ff8`ec9e8000   C:\WINDOWS\System32\KERNELBASE.dll
ModLoad: 00007ff8`ecba0000 00007ff8`ecbc7000   C:\WINDOWS\System32\bcrypt.dll
ModLoad: 00007ff8`ed8b0000 00007ff8`ed95e000   C:\WINDOWS\System32\ADVAPI32.dll
ModLoad: 00007ff8`ed810000 00007ff8`ed8ae000   C:\WINDOWS\System32\msvcrt.dll
ModLoad: 00007ff8`ed080000 00007ff8`ed11c000   C:\WINDOWS\System32\sechost.dll
ModLoad: 00007ff8`ee750000 00007ff8`ee875000   C:\WINDOWS\System32\RPCRT4.dll
ModLoad: 00007ff8`edc80000 00007ff8`edceb000   C:\WINDOWS\System32\WS2_32.dll
ModLoad: 00007ff8`ecbd0000 00007ff8`eccd0000   C:\WINDOWS\System32\ucrtbase.dll
ModLoad: 00007ff8`dbef0000 00007ff8`dbf0b000   C:\WINDOWS\SYSTEM32\VCRUNTIME140.dll
ModLoad: 00000001`80000000 00000001`8005f000   C:\Users\dcbow\Documents\Code\todo\todo-app\target\debug\LIBPQ.dll
ModLoad: 00007ff8`edb70000 00007ff8`edbc6000   C:\WINDOWS\System32\WLDAP32.dll
ModLoad: 00007ff8`ee880000 00007ff8`eefc4000   C:\WINDOWS\System32\SHELL32.dll
ModLoad: 00007ff8`ece10000 00007ff8`ecead000   C:\WINDOWS\System32\msvcp_win.dll
ModLoad: 00007ff8`ed1b0000 00007ff8`ed351000   C:\WINDOWS\System32\USER32.dll
ModLoad: 00007ff8`ecde0000 00007ff8`ece02000   C:\WINDOWS\System32\win32u.dll
ModLoad: 00007ff8`ed050000 00007ff8`ed07b000   C:\WINDOWS\System32\GDI32.dll
ModLoad: 00007ff8`eccd0000 00007ff8`ecddd000   C:\WINDOWS\System32\gdi32full.dll
ModLoad: 00007ff8`dbf10000 00007ff8`dbf1c000   C:\WINDOWS\SYSTEM32\Secur32.dll
ModLoad: 00007ff8`ec010000 00007ff8`ec01c000   C:\WINDOWS\SYSTEM32\CRYPTBASE.DLL
ModLoad: 00007ff8`d9f20000 00007ff8`d9f4b000   C:\WINDOWS\SYSTEM32\VCRUNTIME140D.dll
ModLoad: 00000000`68280000 00000000`682f0000   C:\Program Files\PostgreSQL\14\bin\libintl-9.dll
ModLoad: 00007ff8`d0c80000 00007ff8`d0e47000   C:\WINDOWS\SYSTEM32\ucrtbased.dll
ModLoad: 00000000`66000000 00000000`661bd000   C:\Program Files\PostgreSQL\14\bin\libiconv-2.dll
ModLoad: 00000000`64940000 00000000`64955000   C:\Program Files\PostgreSQL\14\bin\libwinpthread-1.dll
ModLoad: 00007ff8`ec610000 00007ff8`ec641000   C:\WINDOWS\SYSTEM32\SSPICLI.DLL
ModLoad: 00007ff8`ed180000 00007ff8`ed1b0000   C:\WINDOWS\System32\IMM32.DLL
ModLoad: 00007ff8`ecfc0000 00007ff8`ed042000   C:\WINDOWS\System32\bcryptprimitives.dll
ModLoad: 00007ff8`ebde0000 00007ff8`ebe4a000   C:\WINDOWS\system32\mswsock.dll
ModLoad: 00007ff8`ebb00000 00007ff8`ebbcb000   C:\WINDOWS\SYSTEM32\DNSAPI.dll
ModLoad: 00007ff8`ebac0000 00007ff8`ebafb000   C:\WINDOWS\SYSTEM32\IPHLPAPI.DLL
ModLoad: 00007ff8`ed360000 00007ff8`ed368000   C:\WINDOWS\System32\NSI.dll
ModLoad: 00007ff8`dd070000 00007ff8`dd07a000   C:\Windows\System32\rasadhlp.dll
ModLoad: 00007ff8`de360000 00007ff8`de3df000   C:\WINDOWS\System32\fwpuclnt.dll
ntdll!NtTerminateProcess+0x14:
00007ff8`ef0ad2f4 c3              ret

************* Path validation summary **************
Response                         Time (ms)     Location
Deferred                                       srv*
OK                                             C:\Users\dcbow\pg-14.1\libpq
OK                                             C:\Users\dcbow\libpq-092b785fad\libpq
OK                                             C:\Program Files\PostgreSQL\14\debug_symbols

Thread information (only one thread)

0:010> ~
. 10  Id: 1b38.13d0 Suspend: 0 Teb: 0000001f`a3820000 Unfrozen "r2d2-worker-1"
0:010> ~.
. 10  Id: 1b38.13d0 Suspend: 0 Teb: 0000001f`a3820000 Unfrozen "r2d2-worker-1"
      Start: todo_app!std::sys::windows::thread::impl$0::new::thread_start (00007ff7`42b2ac20)
      Priority: 0  Priority class: 32  Affinity: f
0:010> ~#
. 10  Id: 1b38.13d0 Suspend: 0 Teb: 0000001f`a3820000 Unfrozen "r2d2-worker-1"
      Start: todo_app!std::sys::windows::thread::impl$0::new::thread_start (00007ff7`42b2ac20)
      Priority: 0  Priority class: 32  Affinity: f

Stacktrace

0:010> k
 # Child-SP          RetAddr               Call Site
00 0000001f`a4bfcaf8 00007ff8`ef06da38     ntdll!NtTerminateProcess+0x14
01 0000001f`a4bfcb00 00007ff8`ee35e0ab     ntdll!RtlExitUserProcess+0xb8
02 0000001f`a4bfcb30 00007ff8`ed84a155     KERNEL32!ExitProcessImplementation+0xb
03 0000001f`a4bfcb60 00007ff8`ed84a7c5     msvcrt!_crtExitProcess+0x15
04 0000001f`a4bfcb90 00007ff8`ed83f26d     msvcrt!doexit+0x171
05 0000001f`a4bfcc00 00000000`68281886     msvcrt!abort+0x8d
06 0000001f`a4bfd1b0 00000001`80017e87     libintl_9!libintl_bindtextdomain+0x56
07 0000001f`a4bfd1e0 00000001`8001754e     LIBPQ!libpq_binddomain+0x57 [c:\Users\dcbow\Documents\Code\postgres\src\interfaces\libpq\fe-misc.c @ 1290] 
08 0000001f`a4bfd220 00000001`8000dad3     LIBPQ!libpq_gettext+0xe [c:\Users\dcbow\Documents\Code\postgres\src\interfaces\libpq\fe-misc.c @ 1301] 
09 0000001f`a4bfd250 00000001`80004ad6     LIBPQ!emitHostIdentityInfo+0x1e3 [c:\Users\dcbow\Documents\Code\postgres\src\interfaces\libpq\fe-connect.c @ 1718] 
0a 0000001f`a4bfd6d0 00000001`80009774     LIBPQ!PQconnectPoll+0x976 [c:\Users\dcbow\Documents\Code\postgres\src\interfaces\libpq\fe-connect.c @ 2547] 
0b 0000001f`a4bfe160 00000001`8000403e     LIBPQ!connectDBStart+0xd4 [c:\Users\dcbow\Documents\Code\postgres\src\interfaces\libpq\fe-connect.c @ 2063] 
0c 0000001f`a4bfe190 00000001`80005c13     LIBPQ!PQconnectStart+0x5e [c:\Users\dcbow\Documents\Code\postgres\src\interfaces\libpq\fe-connect.c @ 859] 
0d 0000001f`a4bfe1d0 00007ff7`4238f0ca     LIBPQ!PQconnectdb+0x13 [c:\Users\dcbow\Documents\Code\postgres\src\interfaces\libpq\fe-connect.c @ 705] 
0e 0000001f`a4bfe210 00007ff7`4238dd92     todo_app!diesel::pg::connection::raw::RawConnection::establish+0x10a [C:\Users\dcbow\.cargo\registry\src\github.com-1ecc6299db9ec823\diesel-1.4.8\src\pg\connection\raw.rs @ 23] 
0f 0000001f`a4bfe3e0 00007ff7`4236ab09     todo_app!diesel::pg::connection::impl$2::establish+0x22 [C:\Users\dcbow\.cargo\registry\src\github.com-1ecc6299db9ec823\diesel-1.4.8\src\pg\connection\mod.rs @ 50] 
10 0000001f`a4bfe460 00007ff7`4237758c     todo_app!diesel::r2d2::impl$4::connect<diesel::pg::connection::PgConnection>+0x49 [C:\Users\dcbow\.cargo\registry\src\github.com-1ecc6299db9ec823\diesel-1.4.8\src\r2d2.rs @ 86] 
11 0000001f`a4bfe510 00007ff7`42372288     todo_app!r2d2::add_connection::inner::closure$0<diesel::r2d2::ConnectionManager<diesel::pg::connection::PgConnection> >+0xdc [C:\Users\dcbow\.cargo\registry\src\github.com-1ecc6299db9ec823\r2d2-0.8.9\src\lib.rs @ 241] 
12 0000001f`a4bfeb00 00007ff7`42373008     todo_app!scheduled_thread_pool::thunk::impl$0::new::closure$0<tuple$<>,r2d2::add_connection::inner::closure$0>+0x28 [C:\Users\dcbow\.cargo\registry\src\github.com-1ecc6299db9ec823\scheduled-thread-pool-0.2.5\src\thunk.rs @ 20] 
13 0000001f`a4bfeb50 00007ff7`423d4261     todo_app!scheduled_thread_pool::thunk::impl$2::invoke<tuple$<>,tuple$<>,scheduled_thread_pool::thunk::impl$0::new::closure$0>+0x48 [C:\Users\dcbow\.cargo\registry\src\github.com-1ecc6299db9ec823\scheduled-thread-pool-0.2.5\src\thunk.rs @ 50] 
14 0000001f`a4bfebe0 00007ff7`423cfb74     todo_app!scheduled_thread_pool::thunk::Thunk<tuple$<>,tuple$<> >::invoke<tuple$<>,tuple$<> >+0x11 [C:\Users\dcbow\.cargo\registry\src\github.com-1ecc6299db9ec823\scheduled-thread-pool-0.2.5\src\thunk.rs @ 36] 
15 0000001f`a4bfec20 00007ff7`423cf791     todo_app!scheduled_thread_pool::Worker::run_job+0x144 [C:\Users\dcbow\.cargo\registry\src\github.com-1ecc6299db9ec823\scheduled-thread-pool-0.2.5\src\lib.rs @ 364] 
16 0000001f`a4bff0e0 00007ff7`423d1261     todo_app!scheduled_thread_pool::impl$8::run::closure$0+0x41 [C:\Users\dcbow\.cargo\registry\src\github.com-1ecc6299db9ec823\scheduled-thread-pool-0.2.5\src\lib.rs @ 326] 
17 0000001f`a4bff160 00007ff7`423da08b     todo_app!core::panic::unwind_safe::impl$23::call_once<tuple$<>,scheduled_thread_pool::impl$8::run::closure$0>+0x21 [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\core\src\panic\unwind_safe.rs @ 272] 
18 0000001f`a4bff1e0 00007ff7`423da6f3     todo_app!std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<scheduled_thread_pool::impl$8::run::closure$0>,tuple$<> >+0x4b [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\panicking.rs @ 405] 
19 0000001f`a4bff2c0 00007ff7`423d9ecb     todo_app!core::ptr::unique::Unique<dyn$<scheduled_thread_pool::thunk::Invoke<tuple$<>,tuple$<> >,core::marker::Send> >::as_ref<dyn$<scheduled_thread_pool::thunk::Invoke<tuple$<>,tuple$<> >,core::marker::Send> >+0x63
1a 0000001f`a4bff310 00007ff7`423d3271     todo_app!std::panicking::try<tuple$<>,core::panic::unwind_safe::AssertUnwindSafe<scheduled_thread_pool::impl$8::run::closure$0> >+0x8b [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\panicking.rs @ 367] 
1b 0000001f`a4bff4a0 00007ff7`423cf715     todo_app!std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<scheduled_thread_pool::impl$8::run::closure$0>,tuple$<> >+0x21 [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\panic.rs @ 133] 
1c 0000001f`a4bff520 00007ff7`423cf5bf     todo_app!scheduled_thread_pool::Worker::run+0x115 [C:\Users\dcbow\.cargo\registry\src\github.com-1ecc6299db9ec823\scheduled-thread-pool-0.2.5\src\lib.rs @ 326] 
1d 0000001f`a4bff680 00007ff7`423d12ab     todo_app!scheduled_thread_pool::impl$8::start::closure$0+0x1f [C:\Users\dcbow\.cargo\registry\src\github.com-1ecc6299db9ec823\scheduled-thread-pool-0.2.5\src\lib.rs @ 320] 
1e 0000001f`a4bff6c0 00007ff7`423d3c1e     todo_app!std::sys_common::backtrace::__rust_begin_short_backtrace<scheduled_thread_pool::impl$8::start::closure$0,tuple$<> >+0x1b [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\sys_common\backtrace.rs @ 126] 
1f 0000001f`a4bff700 00007ff7`423d122e     todo_app!std::thread::impl$0::spawn_unchecked::closure$1::closure$0<scheduled_thread_pool::impl$8::start::closure$0,tuple$<> >+0xe [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\thread\mod.rs @ 484] 
20 0000001f`a4bff730 00007ff7`423da02c     todo_app!core::panic::unwind_safe::impl$23::call_once<tuple$<>,std::thread::impl$0::spawn_unchecked::closure$1::closure$0>+0xe [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\core\src\panic\unwind_safe.rs @ 272] 
21 0000001f`a4bff770 00007ff7`423da6f3     todo_app!std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<std::thread::impl$0::spawn_unchecked::closure$1::closure$0>,tuple$<> >+0x2c [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\panicking.rs @ 405] 
22 0000001f`a4bff7d0 00007ff7`423d9f8a     todo_app!core::ptr::unique::Unique<dyn$<scheduled_thread_pool::thunk::Invoke<tuple$<>,tuple$<> >,core::marker::Send> >::as_ref<dyn$<scheduled_thread_pool::thunk::Invoke<tuple$<>,tuple$<> >,core::marker::Send> >+0x63
23 0000001f`a4bff820 00007ff7`423d329e     todo_app!std::panicking::try<tuple$<>,core::panic::unwind_safe::AssertUnwindSafe<std::thread::impl$0::spawn_unchecked::closure$1::closure$0> >+0x4a [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\panicking.rs @ 367] 
24 0000001f`a4bff8c0 00007ff7`423d3aad     todo_app!std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<std::thread::impl$0::spawn_unchecked::closure$1::closure$0>,tuple$<> >+0xe [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\panic.rs @ 133] 
25 0000001f`a4bff900 00007ff7`423cc48e     todo_app!std::thread::impl$0::spawn_unchecked::closure$1<scheduled_thread_pool::impl$8::start::closure$0,tuple$<> >+0x10d [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\thread\mod.rs @ 482] 
26 0000001f`a4bffa00 00007ff7`42b2ac6c     todo_app!core::ops::function::FnOnce::call_once<std::thread::impl$0::spawn_unchecked::closure$1,tuple$<> >+0xe [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\core\src\ops\function.rs @ 227] 
27 (Inline Function) --------`--------     todo_app!alloc::boxed::impl$44::call_once+0xb [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\alloc\src\boxed.rs @ 1691] 
28 (Inline Function) --------`--------     todo_app!alloc::boxed::impl$44::call_once+0x16 [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\alloc\src\boxed.rs @ 1691] 
29 0000001f`a4bffa40 00007ff8`ee357034     todo_app!std::sys::windows::thread::impl$0::new::thread_start+0x4c [/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\sys\windows\thread.rs @ 58] 
2a 0000001f`a4bffaa0 00007ff8`ef062651     KERNEL32!BaseThreadInitThunk+0x14
2b 0000001f`a4bffad0 00000000`00000000     ntdll!RtlUserThreadStart+0x21

Switch to frame 7, right before it goes into libintl

0:010> .frame 7
07 0000001f`a4bfd1e0 00000001`8001754e     LIBPQ!libpq_binddomain+0x57 [c:\Users\dcbow\Documents\Code\postgres\src\interfaces\libpq\fe-misc.c @ 1290] 

Local variables

0:010> dv
           ldir = 0x00000001`80056c90 "/share/locale"
     save_errno = 0n0
already_bound = true

Source of the seemingly offending function

static void
libpq_binddomain(void)
{
	static bool already_bound = false;

	if (!already_bound)
	{
		/* bindtextdomain() does not preserve errno */
#ifdef WIN32
		int			save_errno = GetLastError();
#else
		int			save_errno = errno;
#endif
		const char *ldir;

		already_bound = true;
		/* No relocatable lookup here because the binary could be anywhere */
		ldir = getenv("PGLOCALEDIR");
		if (!ldir)
			ldir = LOCALEDIR;
		bindtextdomain(PG_TEXTDOMAIN("libpq"), ldir);
#ifdef WIN32
		SetLastError(save_errno);
#else
		errno = save_errno;
#endif
	}
}

Specified line of crash is actually SetLastError(save_errno);, for some reason. Yet that would make the stack trace wrong...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment