Skip to content

Commit 8b51919

Browse files
committed
CCBC-1672: Fix protocol violation
Protocol violation by sending garbage in front of the operations for new connections. In most of the cases, this bytes getting rejected by the server with connection termination, and libcouchbase successfully reconnects the pipeline after that rendering the issue invisible for the user. But in rare cases the "garbage" might be actual packet header, and the server does not detect problem as everything is passing protocol checks. To fix the issue, the mcreq_wipe_packet have to check pending list of the pipeline and remove everything related to the current detached packet. Change-Id: Ib20a1c11057cf9a1ea66bbb349bcda9976f35c0f Reviewed-on: https://review.couchbase.org/c/libcouchbase/+/232491 Reviewed-by: Michael Reiche <michael.reiche@couchbase.com> Tested-by: Build Bot <build@couchbase.com>
1 parent 21b89aa commit 8b51919

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/mc/mcreq.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ void mcreq_wipe_packet(mc_PIPELINE *pipeline, mc_PACKET *packet)
366366
{
367367
if (!(packet->flags & MCREQ_F_KEY_NOCOPY)) {
368368
if ((packet->flags & MCREQ_F_DETACHED)) {
369+
if (pipeline) {
370+
netbuf_cleanup_packet(&pipeline->nbmgr, packet);
371+
}
369372
free(SPAN_BUFFER(&packet->kh_span));
370373
} else {
371374
netbuf_mblock_release(&pipeline->nbmgr, &packet->kh_span);

src/netbuf/netbuf.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,20 @@ void netbuf_init(nb_MGR *mgr, const nb_SETTINGS *user_settings)
729729
mblock_init(bufpool);
730730
}
731731

732+
void netbuf_cleanup_packet(nb_MGR *mgr, const void *packet)
733+
{
734+
sllist_iterator iter;
735+
736+
SLLIST_ITERFOR(&mgr->sendq.pending, &iter)
737+
{
738+
nb_SNDQELEM *e = SLLIST_ITEM(iter.cur, nb_SNDQELEM, slnode);
739+
if (e->parent == packet) {
740+
sllist_iter_remove(&mgr->sendq.pending, &iter);
741+
mblock_release_ptr(&mgr->sendq.elempool, (char *)e, sizeof(*e));
742+
}
743+
}
744+
}
745+
732746
void netbuf_cleanup(nb_MGR *mgr)
733747
{
734748
sllist_iterator iter;

src/netbuf/netbuf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ void netbuf_init(nb_MGR *mgr, const nb_SETTINGS *settings);
341341
* @param mgr the manager for which to release resources
342342
*/
343343
void netbuf_cleanup(nb_MGR *mgr);
344+
void netbuf_cleanup_packet(nb_MGR *mgr, const void *packet);
344345

345346
/**
346347
* Populates the settings structure with the default settings. This structure

0 commit comments

Comments
 (0)