<commit_before>import domain from 'domain';
import os from 'os';

const connectionResetDomain = domain.create();

connectionResetDomain.on('error', err => {
    // NOTE: The nodejs throw the EPIPE error instead of the ECONNRESET error
    // when the connection is broken in some cases on MacOS
    if (err.code === 'ECONNRESET' || os.type() === 'Darwin' && err.code === 'EPIPE')
        return;

    connectionResetDomain.removeAllListeners('error');
    throw err;
});

export default function (fn) {
    connectionResetDomain.run(fn);
}
<commit_msg>fix `Tests sometimes (frequently) lose connection` (for Linux) (close  #1647) (#1768)<commit_after>import domain from 'domain';
import os from 'os-family';

const connectionResetDomain = domain.create();

connectionResetDomain.on('error', err => {
    // NOTE: The nodejs throw the EPIPE error instead of the ECONNRESET error
    // when the connection is broken in some cases on MacOS and Linux
    if (err.code === 'ECONNRESET' || !os.win && err.code === 'EPIPE')
        return;

    connectionResetDomain.removeAllListeners('error');
    throw err;
});

export default function (fn) {
    connectionResetDomain.run(fn);
}

{'fraction_non_alphanumeric': 0.12818336162988114, 'fraction_numerical': 0.006791171477079796, 'mean_word_length': 4.017021276595744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5277306', 'n_tokens_mistral': 354, 'n_tokens_neox': 345, 'n_words': 113}