Spider cannot boot on 64-bit Windows: CreateFileW dwDesiredAccess declared Fiddle::TYPE_INT cannot hold GENERIC_READ
Describe the bug
On 64-bit Windows the Spider server can never finish booting. ClockworkShmAttach::Win32.receive raises while marshalling arguments to CreateFileW, and because nothing rescues that exception class it aborts the whole boot:
Spider - Failed to start server: bignum too big to convert into 'long'
C:/.../lib/sonicpi/clockwork_shm_attach.rb:204:in 'Fiddle::Function#call'
C:/.../lib/sonicpi/clockwork_shm_attach.rb:203:in 'Integer#times'
C:/.../lib/sonicpi/clockwork_shm_attach.rb:203:in 'SonicPi::ClockworkShmAttach::Win32.receive'
C:/.../lib/sonicpi/clockwork_shm_attach.rb:80:in 'SonicPi::ClockworkShmAttach.receive'
C:/.../lib/sonicpi/clockwork_clock_reader.rb:50:in 'SonicPi::ClockworkClockReader#attach!'
C:/.../lib/sonicpi/link_api.rb:409:in 'SonicPi::LinkAPI#attach_clock_reader!'The GUI then reports Critical error! Could not connect to Sonic Pi Server. The audio engine itself starts fine — this is purely the clockwork shared-memory hand-off.
Root cause
clockwork_shm_attach.rb:194 declares CreateFileW's dwDesiredAccess parameter as Fiddle::TYPE_INT:
create = fn("CreateFileW", [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP,
Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOIDP)dwDesiredAccess is a DWORD. On 64-bit Windows Fiddle marshals TYPE_INT as a signed 32 bit C long, whose maximum is 2**31 - 1 = 2147483647. GENERIC_READ is 0x80000000 = 2147483648 — exactly one past that — so Fiddle raises RangeError while marshalling the arguments, before CreateFileW is ever entered.
Confirmed by direct experiment on Ruby 4.0.7 x64-mingw-ucrt (same arg list, same pipe name):
| Declaration | Result |
|---|---|
Fiddle::TYPE_INT, value 0x80000000 |
RangeError: bignum too big to convert into 'long' |
Fiddle::TYPE_LONG_LONG, value 0x80000000 |
returns INVALID_HANDLE_VALUE, as expected for a missing pipe |
Fiddle::TYPE_INT, value 0x40000000 (control) |
accepted |
The control case pins it down: the only problem is the top bit.
To Reproduce
Build dev on 64-bit Windows and start it. Requires the clockwork SHM path to be reached, which happens on every normal boot. A minimal reproduction of the marshalling failure does not need Sonic Pi at all:
require 'fiddle'
GENERIC_READ = 0x80000000
k32 = Fiddle.dlopen("kernel32.dll")
wide = ("\\\\.\\pipe\\does_not_exist" + "\0").encode("UTF-16LE")
create = Fiddle::Function.new(
k32["CreateFileW"],
[Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP,
Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP],
Fiddle::TYPE_VOIDP)
create.call(wide, GENERIC_READ, 0, nil, 3, 0, nil)
# => RangeError: bignum too big to convert into 'long'Changing that one type to Fiddle::TYPE_LONG_LONG makes the identical call succeed.
Expected behavior
Spider should boot and the GUI should connect. With the parameter widened:
Spider - Runtime Server Initialised
Spider - Registering incoming Spider Server API endpoints
Spider - Booted Successfully.
[API] Sonic Pi Server connection established in 10.3663s
[API] Scope reader attached (scope buffer ready)Environment
- Sonic Pi
dev@aaaef6978,VERSION=5.1.0-beta1 - Windows 11 (10.0.26200) x64, Ruby 4.0.7
x64-mingw-ucrt - Built with Visual Studio 2026 (MSVC 19.51), Qt 6.9.3, SuperSonic v0.83.1
- Also reproduces on Ruby 4.0.5
Two further observations
The failure is much worse than it needs to be.
clockwork_clock_reader.rb:57rescues onlyClockworkShmAttach::AttachErrorandClockworkArena::LayoutError, so thisRangeErrorescapes and kills the boot. That file's own comment says "Every failure is reported, never raised — the caller's answer to 'no snapshot' is the RPC it always had", so the rescue looks like it wants widening. Then a broken hand-off would degrade to the OSC RPC path instead of a hard startup failure.The
Win32module is annotated "Untested here: this machine is not Windows. Kept to the shape of shm_attach::receive's Windows branch, one call per line." — so this path has evidently never executed. There may be further latent issues behind this one. I did noticeReadFile'snNumberOfBytesToReadis also declaredTYPE_INT; that is harmless today because it is passedHELLO_BYTES, but it is worth a look if anyone audits the whole binding.
Issue raised from a source build; I have a PR ready with the one-parameter fix.
Source: sonic-pi-net/sonic-pi