summaryrefslogtreecommitdiff
path: root/jstests/core/tcp_fastopen.js
blob: d63a86c5c5e30a67baceb5836de6c104ffa9e7cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Attempt to verify that connections can make use of TCP_FASTOPEN
// @tags: [multiversion_incompatible, does_not_support_stepdowns]

(function() {
'use strict';

load("jstests/libs/netstat.js");

// Does it make sense to expect TFO support?
try {
    // Both client and server bits must be set to run this test.
    const val = cat("/proc/sys/net/ipv4/tcp_fastopen");
    if ((Number.parseInt(val) & 3) != 3) {
        print("==Skipping test, tcp_fastopen not enabled: " + val);
        return;
    }
} catch (e) {
    // File not found or unreadable, assume no TFO support.
    print("==Skipping test, unable to read /proc/sys/net/ipv4/tcp_fastopen");
    return;
}

const initial = db.serverStatus().network.tcpFastOpen;
printjson(initial);
print("/proc/net/netstat:");
const initialObj = getNetStatObj();
printjson(initialObj);

// If TCPFastOpenBlackhole is 0 or not present, try to run the test. Otherwise,
// we've seen an event, and should skip the test.
if (initialObj.TcpExt.TCPFastOpenBlackhole) {
    print("==Skipping test, host OS has observed a TCPFastOpenBlackhole event");
    return;
}

if (!initial.serverSupported || !initial.clientSupported) {
    print("==Skipping test, one or both setsockopt() calls failed");
    return;
}

function tryShell() {
    const conn = runMongoProgram('mongo', '--port', myPort(), '--eval', ';');
    print("/proc/net/netstat:");
    print(cat("/proc/net/netstat"));
    assert.eq(0, conn);
}

// Initial connect to be sure a TFO cookie is requested and received.
tryShell();

const first = db.serverStatus().network.tcpFastOpen;
printjson(first);

// Second connect using the TFO cookie.
tryShell();

const second = db.serverStatus().network.tcpFastOpen;
printjson(second);

assert.gt(second.accepted, first.accepted, "Second connection did not trigger TFO");
})();