Fix bulk attendance download stalling over WAN / high-latency links#10
Open
hmshb wants to merge 1 commit into
Open
Fix bulk attendance download stalling over WAN / high-latency links#10hmshb wants to merge 1 commit into
hmshb wants to merge 1 commit into
Conversation
…ency links getAttendances() reliably returns the full history on a LAN but truncates to the first ~2 chunks (often surfacing as "0 logs" or only old records) when the device is reached across the internet / a slow link. This is a long-standing pain point (see node-zklib#31). Two root causes in readWithBuffer, plus one knob: 1. Chunk requests were fired all at once (`for i in numberChunks: sendChunkRequest`). On a LAN the device keeps up; over a high-latency link its send buffer fills faster than the link drains and the later chunks never arrive, truncating the download. Now requests one chunk at a time, waiting for each to fully arrive before requesting the next. 2. The inter-packet timeout was hardcoded to 10000ms and ignored the constructor `timeout`. Now respects `this.timeout` (falls back to 10s), so slow links can be given more time. 3. New optional `maxChunk` constructor arg (default unchanged at 65472). Lowering it (e.g. 8184) makes each chunk individually more robust; on a real ZKTeco K50 behind PPPoE this was the difference between a download that stalled at ~3,200 records and one that pulled the full ~9,900 in ~18s. Fully backward compatible — omit it and behaviour is unchanged. Verified against a live K50 over a WAN link.
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.
Problem
getAttendances()works perfectly on a LAN but truncates the bulk download to roughly the first ~2 chunks when the device is reached across the internet or any slow / high-latency link. It typically surfaces asFetched 0 logsor only old records, with the recent punches (at the tail of the history) never arriving. This is a long-standing pain point — see node-zklib#31.I traced it on a live ZKTeco K50 behind PPPoE, reached from a cloud server. The connection, voice test and record-count all worked; only the bulk download stalled — consistently at the same byte boundary regardless of timeout.
Root causes (in
readWithBuffer)All chunk requests were fired up front (
for (i=0..numberChunks) sendChunkRequest(...)). On a LAN the device keeps up. Over a high-latency link the device's send buffer fills faster than the link drains, the later chunks never arrive, and the stream wedges — truncating the download.The inter-packet timeout was hardcoded to
10000ms and ignored the constructortimeout, so slow links couldn't be given more breathing room.Changes (all backward compatible)
pyzk) use.timeoutfor the inter-packet wait instead of the hardcoded 10s (falls back to 10s when unset).maxChunkconstructor argument (default unchanged at65472). Lowering it (e.g.8184) makes each chunk individually more robust on poor links.Result
On the real K50 over the WAN link this was the difference between a download that stalled at ~3,200 records (months-old data) and one that pulled the full ~9,900 records including same-day punches in ~18s.
No API breakage: omit
maxChunkand behaviour is identical to before. Verified against a live device;node -cclean.