Skip to content

Conversation

@ucko
Copy link
Contributor

@ucko ucko commented May 30, 2024

Don't bother trying to receive data following a packet marked as last; rather, bail if still short. Whenever bailing, close the socket on the way out to contain the damage from having fallen out of sync.

Split from #555.

Don't bother trying to receive data following a packet marked as last;
rather, bail if still short.  Whenever bailing, close the socket on
the way out to contain the damage from having fallen out of sync.

Signed-off-by: Aaron M. Ucko <[email protected]>
}
need -= have;
if (TDS_UNLIKELY(tds_read_packet(tds) < 0))
if (TDS_UNLIKELY(tds->recv_packet->capacity < 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capacity can't be so small

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point; I just wanted to preclude any possibility that the following array access would be invalid.

need -= have;
if (TDS_UNLIKELY(tds_read_packet(tds) < 0))
if (TDS_UNLIKELY(tds->recv_packet->capacity < 2
|| tds->in_buf[1] != 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you want to test only the final bit and not all the flags. It makes sense, if no more packets are expected data should not continue on next packet. Wondering if tds_get_n would be called for first bytes of the packet series. Not sure if this can even happen however. I don't think cancellation apply here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah, testing just the low-order bit is more appropriate, though I'm not sure how much difference it makes in practice.

The situation originally motivating this change was canceling blob retrieval, which at least in the case of the OpenServer instance I was using, could yield a truncated row response giving a blob's full length but containing only part of its body, leading to loss of synchronization that would otherwise typically culminate in hangs. Perhaps the server should have acknowledged cancellation more clearly, but it did at least set that flag correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! So you are telling the way Open Server handles cancellation is different? Maybe we can support it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, at least historically. Maybe it's been fixed since, but a little extra caution here can't hurt.

@freddy77
Copy link
Contributor

freddy77 commented Dec 7, 2024

Merged, with minor changes. Sorry for the delay. One thing that puzzled me is why it did not fail when we get to a new packet; probably the packet always start with a byte read by tds_get_byte.

@freddy77 freddy77 closed this Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants