Repository navigation
fix: Remove dead Windows WSAStartup() workaround - #647
Conversation
`src/RPostgres-init.c` defined `R_init_mypackage()` and `R_unload_mylib()`, names R never looks up, so the code has never run. Its rationale is gone as well: since PostgreSQL 9.5, libpq calls `WSAStartup()` once per process in `pqMakeEmptyPGconn()` and never calls `WSACleanup()`, so closing the last connection no longer tears down Winsock. All libpq builds RPostgres links on Windows are far newer. Closes #636. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
Question: Delete the dead
|
With `src/RPostgres-init.c` gone, `src/` has no C sources left, and `R CMD check` notes that `PKG_CFLAGS` is set without any corresponding files. `src/Makevars.win` sets no `PKG_CFLAGS`, and `configure` passes its own flags through `PKG_CPPFLAGS`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
The file was removed in #647. The source list again matches `src/*.c`, `src/*.cpp`, and `src/*.h`, and CMake configures. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
…akeLists.txt` (#656) * build: Use vendored Boost with Rtools and drop `logging.cpp` from `CMakeLists.txt` The Rtools branch of `src/Makevars.win` now passes `-Ivendor`, like the rwinlib branch. It comes before the pkg-config flags, so the vendored Boost wins over the copy Rtools ships in its include directory. `src/CMakeLists.txt` no longer lists `logging.cpp`, which was removed in #545. CMake now configures again. Closes #637. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g * build: Drop `RPostgres-init.c` from `CMakeLists.txt` The file was removed in #647. The source list again matches `src/*.c`, `src/*.cpp`, and `src/*.h`, and CMake configures. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g --------- Co-authored-by: Claude <[email protected]>
Resolves the conflict in `.Rbuildignore` by keeping the entries from both sides. The explicit recipe for `nanoarrow.o` keeps its symbols hidden now that `main` no longer sets `PKG_CFLAGS` (#647). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
Closes #636.
This PR deletes
src/RPostgres-init.c. The file definedR_init_mypackage()andR_unload_mylib(), which R never looks up (it looks forR_init_RPostgres()andR_unload_RPostgres()), so theWSAStartup()call it contains has never run since it was added in 2015. Rather than wiring it up via[[cpp11::init]], this PR removes it, because libpq made the workaround unnecessary long ago.Evidence
The workaround follows an old paragraph of the libpq docs: libpq used to call
WSAStartup()when a connection started andWSACleanup()when it was freed, so closing the last connection unloaded Winsock and the next connect paid to load it again. That describes libpq up to 9.4:REL9_4_STABLEfe-connect.c callsWSAStartup(MAKEWORD(1, 1), &wsaData)inmakeEmptyPGconn()andWSACleanup()infreePGconn(), and the 9.4libpq.sgmlstill has the paragraph.Since the November 2020 minor releases (13.1, 12.5, 11.10, 10.15, 9.6.20, 9.5.24) and in every release from 14 on, libpq calls
WSAStartup(MAKEWORD(2, 2), &wsaData)once per process, guarded by astatic bool wsastartup_done, and never callsWSACleanup(). Earlier releases, such as 9.5.0, 12.0 and 13.0, still start and clean up Winsock per connection. The source comment says: "the Windows documentation says that we should eventually do a matching WSACleanup() call, but experience suggests that that is at least as likely to cause problems as fix them. So we don't." The current tips of the branches fromREL9_5_STABLEthroughREL_18_STABLEandpqMakeEmptyPGconn()on master all have it, and so do the tagsREL_13_2andREL_15_12that RPostgres bundles.Every libpq that RPostgres bundles on Windows has the fix: the Rtools libpq, or the bundles that
tools/winlibs.Rdownloads (libpq 15.12, or 13.2 for R < 4.2). So the Winsock reference count never returns to zero once the first connection is made, and the workaround has nothing left to prevent. Even if it were fixed, it would only add a second reference that libpq doesn't need. The other two defects from the issue, theNULLlpWSAData(which would giveWSAEFAULT) and the missing unload hook, go away along with the file.src/CMakeLists.txtstill listsRPostgres-init.c. That file is generated bycynkrathis::use_cmakelists()for IDE use only, R's build doesn't read it, and it is already stale (it listslogging.cpp, which doesn't exist). I left it alone so this PR doesn't overlap with #637, which regenerates that file; whichever of the two merges second regenerates it again.With the file gone,
src/has no C sources left, soR CMD checknotes "PKG_CFLAGS set in 'src/Makevars' / 'src/Makevars.in' without any corresponding files", which fails the CI smoke test. The second commit therefore dropsPKG_CFLAGS=$(C_VISIBILITY)fromsrc/Makevars.in.src/Makevars.winsets noPKG_CFLAGS, andconfigurepasses its flags throughPKG_CPPFLAGS(@cflags@), so nothing else writes it.This interacts with #635, which builds
src/vendor/nanoarrow/nanoarrow.cthrough make's implicit rule and so relies onPKG_CFLAGS=$(C_VISIBILITY)for-fvisibility=hidden. The two branches merge without a textual conflict, but the merged tree compilesnanoarrow.cwithout-fvisibility=hidden, andRPostgres.sothen exports 71 nanoarrow symbols, compared with 0 on #635 alone.R CMD checkpasses on the merged tree, since it doesn't count the C file undervendor/. Whichever of the two merges second needs a follow-up to restore the hidden visibility for that object, for example by passing$(C_VISIBILITY)in an explicit recipe forvendor/nanoarrow/nanoarrow.o.Tests
R_init_RPostgres, as before.R CMD buildfollowed by_R_CHECK_FORCE_SUGGESTS_=false R CMD check --no-manual --no-tests: with the first commit alone, "checking use of PKG_*FLAGS in Makefiles ... NOTE" appears. With the second commit, that check is OK and the status is OK.Coordinated in #631. Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
Generated by Claude Code