|
33 | 33 | #include <unistd.h>
|
34 | 34 |
|
35 | 35 |
|
36 |
| -/* Size of the streaming replication protocol header */ |
37 |
| -#define STREAMING_HEADER_SIZE (1+8+8+8) |
| 36 | +/* Size of the streaming replication protocol headers */ |
| 37 | +#define STREAMING_HEADER_SIZE (1+sizeof(WalDataMessageHeader)) |
| 38 | +#define STREAMING_KEEPALIVE_SIZE (1+sizeof(PrimaryKeepaliveMessage)) |
38 | 39 |
|
39 | 40 | const XLogRecPtr InvalidXLogRecPtr = {0, 0};
|
40 | 41 |
|
@@ -374,18 +375,33 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
|
374 | 375 | progname, PQerrorMessage(conn));
|
375 | 376 | return false;
|
376 | 377 | }
|
377 |
| - if (r < STREAMING_HEADER_SIZE + 1) |
| 378 | + if (copybuf[0] == 'k') |
378 | 379 | {
|
379 |
| - fprintf(stderr, _("%s: streaming header too small: %i\n"), |
380 |
| - progname, r); |
381 |
| - return false; |
| 380 | + /* |
| 381 | + * keepalive message, sent in 9.2 and newer. We just ignore |
| 382 | + * this message completely, but need to forward past it |
| 383 | + * in our reading. |
| 384 | + */ |
| 385 | + if (r != STREAMING_KEEPALIVE_SIZE) |
| 386 | + { |
| 387 | + fprintf(stderr, _("%s: keepalive message is incorrect size: %i\n"), |
| 388 | + progname, r); |
| 389 | + return false; |
| 390 | + } |
| 391 | + continue; |
382 | 392 | }
|
383 |
| - if (copybuf[0] != 'w') |
| 393 | + else if (copybuf[0] != 'w') |
384 | 394 | {
|
385 | 395 | fprintf(stderr, _("%s: unrecognized streaming header: \"%c\"\n"),
|
386 | 396 | progname, copybuf[0]);
|
387 | 397 | return false;
|
388 | 398 | }
|
| 399 | + if (r < STREAMING_HEADER_SIZE + 1) |
| 400 | + { |
| 401 | + fprintf(stderr, _("%s: streaming header too small: %i\n"), |
| 402 | + progname, r); |
| 403 | + return false; |
| 404 | + } |
389 | 405 |
|
390 | 406 | /* Extract WAL location for this block */
|
391 | 407 | memcpy(&blockpos, copybuf + 1, 8);
|
|
0 commit comments