marcelvanherk
I got back to this as the issue still causes annoying failures when querying the webserver.
This time, I used Claude as well to help with the debugging.
Claude analysis as follows (diagonsed with the source code of v1.5.0f):
What the log lines actually mean
The four messages are both halves of the same failed association, which is why they look confusing:
- No valid presentation contexts/transfer syntax found in 0 candidates — server side, pdu.cxx:483. The 0 is the total number of transfer syntaxes across all proposed presentation contexts. The incoming A-ASSOCIATE-RQ literally offered none.
- In 1 presentation contexts — one presentation context was proposed. That matches dicomget's first association exactly: it proposes a single abstract syntax (StudyRootQuery) for the C-FIND that fetches SOP class UIDs before the actual C-GET.
- No accepted presentation contexts/transfer syntax found in 1 candidates — SCU side, pdu.cxx:539. Same association, seen from the other end after the server returned the rejection.
- multiplex: connection terminated — ServerChild giving up.
PDU.Connect() then returns FALSE, luadicomget does return 0, so r is nil in Lua and r:Serialize(...) blows up. Everything downstream is a consequence.
Root cause
ExtendedPDU_Service overrides AddTransferSyntaxs() (nkiqrsop.cpp:5103). The last thing that function does is:
if (strchr(RequestedCompressionType, '!')==NULL)
{ uid.Set("1.2.840.10008.1.2"); // ImplicitLittleEndian
TrnSyntax.Set(uid);
PresContext.AddTransferSyntax(TrnSyntax);
}
That is the only line that guarantees a presentation context gets at least one transfer syntax. Now the two problems:
- RequestedCompressionType[64] is never initialised. The ExtendedPDU_Service constructor (nkiqrsop.hpp:57) sets L, VariableVRs and ThreadNum — but not this member.
- luadicomget never calls SetRequestedCompressionType(). At dgate.cpp:28559 it declares ExtendedPDU_Service PDU;, reads compress out of GetACRNema()… and then never applies it. Compare luadicomstore at 28711–28712, which correctly does SetRequestedCompressionType("") followed by SetRequestedCompressionType(compress). Every other caller in the codebase (5420, 9787, 19688–19701) sets it too.
So on every dicomget(), that 64-byte buffer holds uninitialised stack memory. Usually the garbage doesn't start with j/J, isn't ul/ub/ue, and — crucially — contains no 0x21 byte before its first NUL, so the guard passes and Implicit LE is added. It works.
Occasionally the stack garbage happens to contain a !. The guard fails, no transfer syntax is added, and Conquest sends a presentation context with zero transfer syntaxes. That's your "0 candidates".
That's exactly why it's sporadic, why it isn't reproducible on demand, and why an immediate retry often doesn't clear it — it depends on whatever the thread's stack happened to contain, which can persist across a retry that follows the same code path.
luadicomquery (dgate.cpp:27792) has the identical defect. dicomecho uses a plain PDU_Service, whose base AddTransferSyntaxs unconditionally adds Implicit LE, so it's immune — which fits if you've never seen echoes fail this way.
Claude's Recommended Fix
Either of these; I'd do both.
In nkiqrsop.hpp, constructor body, alongside the existing memset:
RequestedCompressionType[0] = 0;
AcceptedCompressionType[0] = 0;
And in luadicomget (dgate.cpp, right after the GetACRNema block around 28572), matching what luadicomstore does:
PDU.SetRequestedCompressionType("");
Use "" rather than compress unless you actually want the AE's configured compression negotiated on the retrieve — passing compress is arguably the original intent, but it changes negotiation behaviour, so keep the two changes separate.
Two related things worth knowing
PDU_Service::Multiplex(int) (pdu.cxx:690) deliberately no longer aborts when AAssociateRQ::Read fails — a 20131106 change swapped the return FALSE for a debug-only message. So genuine truncated reads get silently interrogated as half-parsed associations. It isn't what bit you here, but it means this class of error always presents as a negotiation failure rather than "connection lost". Related: Buffer::Read zero-fills and returns FALSE on failure, and every caller in aarq.cxx ignores that return value.
Also PDU_Service::Close() (pdu.cxx:701) returns early without calling Link.Close() if the A-RELEASE-RP read fails, and nothing clears the inherited Buffer::Incoming queue between associations. Since luadicomget reuses one PDU object for the C-FIND and then the C-GET, that's a second, independent way for those two associations to desynchronise. Worth fixing while you're in there.