refactor: use curl_global_init_mem with pg allocators#223
Draft
steve-chavez wants to merge 1 commit intosupabase:masterfrom
Draft
refactor: use curl_global_init_mem with pg allocators#223steve-chavez wants to merge 1 commit intosupabase:masterfrom
steve-chavez wants to merge 1 commit intosupabase:masterfrom
Conversation
Uses `curl_global_init_mem(CURL_GLOBAL_DEFAULT, net_malloc, net_free, net_realloc, net_strdup, net_calloc)` to keep better track of memory allocation by curl. The aim is to fix supabase#216. Unfortunately this currently segfaults when reaching 2 iterations: ```sql -- do twice select net.http_get('http://localhost:8080/pathological?status=200') from generate_series(1,10); select net.http_get('http://localhost:8080/pathological?status=200') from generate_series(1,10); -- or once (this will do two iterations since the batch size defaults to 200) select net.http_get('http://localhost:8080/pathological?status=200') from generate_series(1,300); ``` The logs: ``` 2025-08-14 17:55:08.571 -05 [643019] DEBUG: net_realloc(palloc): a((nil)), sz(32) 2025-08-14 17:55:08.571 -05 [643019] DEBUG: net_malloc: sz(32) 2025-08-14 17:55:08.665 -05 [643013] LOG: background worker "pg_net 0.19.5 worker" (PID 643019) was terminated by signal 11: Segmentation fault ``` Using `gdb` (via convenience `sudo xpg gdb`) will show that this will always fail when hitting curl functions: ``` Curl_attach_connection Curl_llist_count Curl_conn_is_alive ``` Which are called when using `curl_multi_socket_action` in our codebase in https://github.com/supabase/pg_net/blob/a7792bfd913c7859e14025d606624982706c2a7f/src/worker.c#L320-L336 Unfortunately this is quite hard to debug, it might be a bug in curl itself.
Member
Author
I think this is because some curl allocations are done in sub memory contexts and the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uses
curl_global_init_mem(CURL_GLOBAL_DEFAULT, net_malloc, net_free, net_realloc, net_strdup, net_calloc)to keep better track of memory allocation by curl.The aim is to fix #216.
Unfortunately this currently segfaults when reaching 2 iterations:
The logs:
Using
gdb(via conveniencesudo xpg gdb) will show that this will always fail when hitting curl functions:Which are called when using
curl_multi_socket_actionin our codebase inpg_net/src/worker.c
Lines 320 to 336 in a7792bf
Unfortunately this is quite hard to debug, it might be a bug in curl itself.