Google-api-nodejs-client: Erreur ECONNRESET avec une grande feuille lue avec v 32.0.0

Créé le 29 juin 2018  ·  3Commentaires  ·  Source: googleapis/google-api-nodejs-client

Salut, après la mise à niveau vers la nouvelle API de feuilles basée sur Axios, j'ai du mal à lire une feuille assez volumineuse,
après quelques minutes, il génère une erreur, voir ci-dessous.

Je suis capable de lire des feuilles plus petites, mais la demande est notablement plus lente par rapport à la v24 du client.

Je lis la feuille comme suit :

const response = await sheetsAPI.spreadsheets.get({
    auth: jwtClient,
    spreadsheetId,
    includeGridData: true
  });

(testé avec NodeJS 9.9.0 et le dernier 10.5)

{ Error: read ECONNRESET
    at TLSWrap.onread (net.js:602:25)
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  syscall: 'read',
  config: 
   { adapter: [Function: httpAdapter],
     transformRequest: { '0': [Function: transformRequest] },
     transformResponse: { '0': [Function: transformResponse] },
     timeout: 0,
     xsrfCookieName: 'XSRF-TOKEN',
     xsrfHeaderName: 'X-XSRF-TOKEN',
     maxContentLength: 2147483648,
     validateStatus: [Function],
     headers: 
      { Accept: 'application/json, text/plain, */*',
        'Accept-Encoding': 'gzip',
        'User-Agent': 'google-api-nodejs-client/32.0.0 (gzip)',
        Authorization: 'Bearer ya29.c.xxx-xxx-xxx' },
     method: 'get',
     url: 'https://sheets.googleapis.com/v4/spreadsheets/xxx',
     paramsSerializer: [Function],
     data: undefined,
     params: { includeGridData: true } },
  request: 
   Writable {
     _writableState: 
      WritableState {
        objectMode: false,
        highWaterMark: 16384,
        finalCalled: false,
        needDrain: false,
        ending: false,
        ended: false,
        finished: false,
        destroyed: false,
        decodeStrings: true,
        defaultEncoding: 'utf8',
        length: 0,
        writing: false,
        corked: 0,
        sync: true,
        bufferProcessing: false,
        onwrite: [Function: bound onwrite],
        writecb: null,
        writelen: 0,
        bufferedRequest: null,
        lastBufferedRequest: null,
        pendingcb: 0,
        prefinished: false,
        errorEmitted: false,
        bufferedRequestCount: 0,
        corkedRequestsFree: [Object] },
     writable: true,
     _events: 
      { response: [Function: handleResponse],
        error: [Function: handleRequestError] },
     _eventsCount: 2,
     _maxListeners: undefined,
     _options: 
      { protocol: 'https:',
        maxRedirects: 21,
        maxBodyLength: 2147483648,
        path: '/v4/spreadsheets/xxx?includeGridData=true',
        method: 'get',
        headers: [Object],
        agent: undefined,
        auth: undefined,
        hostname: 'sheets.googleapis.com',
        port: null,
        nativeProtocols: [Object],
        pathname: '/v4/spreadsheets/xxx',
        search: '?includeGridData=true' },
     _redirectCount: 0,
     _redirects: [],
     _requestBodyLength: 0,
     _requestBodyBuffers: [],
     _onNativeResponse: [Function],
     _currentRequest: 
      ClientRequest {
        _events: [Object],
        _eventsCount: 6,
        _maxListeners: undefined,
        output: [],
        outputEncodings: [],
        outputCallbacks: [],
        outputSize: 0,
        writable: true,
        _last: true,
        upgrading: false,
        chunkedEncoding: false,
        shouldKeepAlive: false,
        useChunkedEncodingByDefault: false,
        sendDate: false,
        _removedConnection: false,
        _removedContLen: false,
        _removedTE: false,
        _contentLength: 0,
        _hasBody: true,
        _trailer: '',
        finished: true,
        _headerSent: true,
        socket: [TLSSocket],
        connection: [TLSSocket],
        _header: 'GET /v4/spreadsheets/xxx?includeGridData=true HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nAccept-Encoding: gzip\r\nUser-Agent: google-api-nodejs-client/32.0.0 (gzip)\r\nAuthorization: Bearer ya29.c.xxx-xxx-xxx\r\nHost: sheets.googleapis.com\r\nConnection: close\r\n\r\n',
        _onPendingData: [Function: noopPendingOutput],
        agent: [Agent],
        socketPath: undefined,
        timeout: undefined,
        method: 'GET',
        path: '/v4/spreadsheets/xxx?includeGridData=true',
        _ended: false,
        res: [IncomingMessage],
        aborted: undefined,
        timeoutCb: null,
        upgradeOrConnect: false,
        parser: null,
        maxHeadersCount: null,
        _redirectable: [Circular],
        [Symbol(isCorked)]: false,
        [Symbol(outHeadersKey)]: [Object] },
     _currentUrl: 'https://sheets.googleapis.com/v4/spreadsheets/xxx?includeGridData=true' },
  response: undefined }
p2 bug

Commentaire le plus utile

Donc, en creusant, j'ai trouvé ce tas de fumier de cheval dans le code axios

        stream.on('data', function handleStreamData(chunk) {
          responseBuffer.push(chunk);

          // make sure the content length is not over the maxContentLength if specified
          if (config.maxContentLength > -1 && Buffer.concat(responseBuffer).length > config.maxContentLength) {
            reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
              config, null, lastRequest));
          }
        });

Qui, sensé, aurait pu faire une allocation de tampon dans une boucle serrée juste pour vérifier sa longueur m'échappe.

@ovaris @JustinBeckwith ajoutez simplement maxContentLength: -1, aux paramètres de votre demande à l'api et cela fonctionnera rapidement. Ainsi:

    const data =  await sheets.spreadsheets.get(
        {
            spreadsheetId,
            includeGridData: true,
            ranges: "MAIN"
        },
        {
            maxContentLength: -1,
            params: {
                fields:
                    "sheets(data(rowData(values(userEnteredFormat/backgroundColor,userEnteredValue)),startColumn,startRow))"
            }
        }
    );

Tous les 3 commentaires

Je vois le même bug. L'utilisation de la bibliothèque de requêtes pour faire la même requête https au lieu d'axios fonctionne 10 fois plus vite.

Donc, en creusant, j'ai trouvé ce tas de fumier de cheval dans le code axios

        stream.on('data', function handleStreamData(chunk) {
          responseBuffer.push(chunk);

          // make sure the content length is not over the maxContentLength if specified
          if (config.maxContentLength > -1 && Buffer.concat(responseBuffer).length > config.maxContentLength) {
            reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
              config, null, lastRequest));
          }
        });

Qui, sensé, aurait pu faire une allocation de tampon dans une boucle serrée juste pour vérifier sa longueur m'échappe.

@ovaris @JustinBeckwith ajoutez simplement maxContentLength: -1, aux paramètres de votre demande à l'api et cela fonctionnera rapidement. Ainsi:

    const data =  await sheets.spreadsheets.get(
        {
            spreadsheetId,
            includeGridData: true,
            ranges: "MAIN"
        },
        {
            maxContentLength: -1,
            params: {
                fields:
                    "sheets(data(rowData(values(userEnteredFormat/backgroundColor,userEnteredValue)),startColumn,startRow))"
            }
        }
    );

Salutations les gens! Je suis sûr à 99% que cela a été corrigé dans la v37 :) Si vous rencontrez toujours des problèmes, faites-le moi savoir !

Cette page vous a été utile?
0 / 5 - 0 notes

Questions connexes

dibeesh picture dibeesh  ·  4Commentaires

CyberT33N picture CyberT33N  ·  3Commentaires

streamnsight picture streamnsight  ·  4Commentaires

skiod picture skiod  ·  3Commentaires

Chethandsagar picture Chethandsagar  ·  4Commentaires