Repository navigation
[#41] Use AllocateFile and PG_TRY/PG_CATCH in pgmoneta_ext_receive_file_chunk - #42
hardikkaurani wants to merge 1 commit into
Conversation
|
Hi @jesperpedersen, This PR is ready for review. Summary of Changes:
|
|
Step 2 of the new test can't pass: for The |
ed5a863 to
f894282
Compare
|
@Pranav-error Thanks for catching that! Updated PGMONETA_EXT_BASE64_ERROR_REGEX in est/lib/pgmoneta_ext_test.c to match Failed to decode Base64 data from �ase64_decode(), noted the VARDATA(decoded_data) fix in the commit message, and squashed/rebased onto main. |
|
The regex fix looks right, but f894282 also undoes 4bff1ac (Support PostgreSQL 19): the |
f894282 to
ef38681
Compare
|
@Pranav-error Good catch — restored |
…ceive_file_chunk Use PostgreSQL AllocateFile/FreeFile and PG_TRY/PG_CATCH in pgmoneta_ext_receive_file_chunk() so file descriptors and flock() locks are released on ereport(ERROR). Also write decoded bytes via VARDATA(decoded_data) instead of the varlena header. Signed-off-by: Hardik Kaurani <[email protected]>
|
Re-checked at ef38681: only the #41 changes now, and |
|
@Pranav-error Thanks for verifying at |
Fixes #41
Description
In
pgmoneta_ext_receive_file_chunk(), target files were opened using bare libcfopen()and locked withflock()without PostgreSQL resource tracking or exception handling. Ifbase64_decode()orfwrite()raised anereport(ERROR), PostgreSQL aborted the transaction viasiglongjmp(), leaving the file descriptor open and the advisoryflock()lock held in the PostgreSQL backend process. Any subsequent chunk upload to that file within the same backend session failed with:Changes
PostgreSQL Tracked File APIs (
AllocateFile/FreeFile):fopen()/fclose()with PostgreSQL'sAllocateFile()andFreeFile().<storage/fd.h>.Exception & Lock Safety (
PG_TRY/PG_CATCH):PG_TRY()/PG_CATCH().volatilequalification to local variables examined inPG_CATCH()acrosssiglongjmp().PG_CATCH(), cleaned updecoded_dataif non-NULL, and reset pointers toNULLto prevent double-free or double-close.flock(fd, LOCK_UN)on both error (ereport(WARNING)with%mso as not to interruptPG_RE_THROW()) and success paths (ereport(ERROR)with%mafter closing the file).VARDATA(decoded_data)so the actual payload (rather than the varlena length header) is written to disk.Regression Tests & Test Framework Improvements:
test/lib/pgmoneta_ext_test.c, updatedexecute_command()to inspectpclose()status usingWIFEXITED()andWEXITSTATUS()with<sys/wait.h>.test_pgmoneta_ext_receive_file_chunk:ON_ERROR_STOP=1) and expected error message (Failed to decode base64 chunk) without leaking lock/handle.hello worldmore data.TCasewith checked setup and teardown fixtures to ensure reliable file cleanup even on assertion failure.Authors:
AUTHORS.