You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2021/01/14 14:22:04 UTC

[GitHub] [couchdb-nano] thescrublet opened a new issue #252: scrubLog functionality can fail on JSON circular reference

thescrublet opened a new issue #252:
URL: https://github.com/apache/couchdb-nano/issues/252


   <!--- Provide a general summary of the issue in the Title above -->
   Consider the following code in relax:
   `
   req.httpAgent = cfg.requestDefaults.agent || defaultHttpAgent
   req.httpsAgent = cfg.requestDefaults.agent || defaultHttpsAgent
   
   // scrub and log
   const scrubbedReq = JSON.parse(JSON.stringify(req))
   `
   
   I'm having issues where the JSON.stringify can fail due to circular references in Socket. Traditionally I've avoided logging Socket objects in my code because I've run into this problem before.
   
   ## Expected Behavior
   Code functions as designed.
   
   ## Current Behavior
   TypeError: Converting circular structure to JSON
       --> starting at object with constructor 'Socket'
       |     property '_httpMessage' -> object with constructor 'ClientRequest'
       --- property 'socket' closes the circle {"timestamp":"2021-01-14T14:13:20.913Z"}
   
   ## Possible Solution
   I believe the scrubLog should happen BEFORE setting the req.httpAgent and req.httpsAgent fields. If you need to get that socket information, debug it.
   
   ## Steps to Reproduce (for bugs)
   I'm still trying to figure out why this happens sometimes and not others. For example, I was getting the error on changesReader.start at one point, but figured out my code was improperly calling the function multiple times. My current code seems fine though:
   `
   this.myDb.changesReader.start({ includeDocs: true }).on("batch", (batch) => { ... }.on("error", (error) => { console.error(error) }`
   
   ## Context
   I'm listening for any event in the database.
   
   ## Your Environment
   <!--- Include as many relevant details about the environment you experienced the bug in -->
   * Version used: 9.0.2
   * Browser Name and version: NodeJS 14
   * Operating System and version (desktop or mobile): Docker running CentOS 7
   * Link to your project: private internal
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb-nano] glynnbird closed issue #252: scrubLog functionality can fail on JSON circular reference

Posted by GitBox <gi...@apache.org>.
glynnbird closed issue #252:
URL: https://github.com/apache/couchdb-nano/issues/252


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb-nano] Dryymoon edited a comment on issue #252: scrubLog functionality can fail on JSON circular reference

Posted by GitBox <gi...@apache.org>.
Dryymoon edited a comment on issue #252:
URL: https://github.com/apache/couchdb-nano/issues/252#issuecomment-781154445


   How to add custom agent:
   ```javascript
   const agent = new http.Agent();
   agent.toJSON = () => null;
   const couchdb = require('nano')({
     url: 'http://admin:admin@localhost:5984',
     requestDefaults: {
       agent
     }
   });
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb-nano] jjd314 commented on issue #252: scrubLog functionality can fail on JSON circular reference

Posted by GitBox <gi...@apache.org>.
jjd314 commented on issue #252:
URL: https://github.com/apache/couchdb-nano/issues/252#issuecomment-762324453


   If you are using a custom agent in requestDefaults (as described [in the docs](https://github.com/apache/couchdb-nano#pool-size-and-open-sockets)), the same problem occurs, because the agent is copied directly into the request [when it is created](https://github.com/apache/couchdb-nano/blob/1680101d5f16c4c8f78934f7a938947bc04c6db8/lib/nano.js#L248).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb-nano] Dryymoon edited a comment on issue #252: scrubLog functionality can fail on JSON circular reference

Posted by GitBox <gi...@apache.org>.
Dryymoon edited a comment on issue #252:
URL: https://github.com/apache/couchdb-nano/issues/252#issuecomment-781154445


   How to add custom agent:
   ```javascript
   const agent = new http.Agent();
   agent.toJSON = () => null; // This line help bypass Circular json error
   const couchdb = require('nano')({
     url: 'http://admin:admin@localhost:5984',
     requestDefaults: {
       agent
     }
   });
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb-nano] glynnbird commented on issue #252: scrubLog functionality can fail on JSON circular reference

Posted by GitBox <gi...@apache.org>.
glynnbird commented on issue #252:
URL: https://github.com/apache/couchdb-nano/issues/252#issuecomment-760707819


   Should be fixed in 9.0.3


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb-nano] glynnbird commented on issue #252: scrubLog functionality can fail on JSON circular reference

Posted by GitBox <gi...@apache.org>.
glynnbird commented on issue #252:
URL: https://github.com/apache/couchdb-nano/issues/252#issuecomment-760241834


   Thanks for reporting @thescrublet . A fix is on its way through Travis now.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb-nano] dsebastien commented on issue #252: scrubLog functionality can fail on JSON circular reference

Posted by GitBox <gi...@apache.org>.
dsebastien commented on issue #252:
URL: https://github.com/apache/couchdb-nano/issues/252#issuecomment-761104613


   I confirm that it now works perfectly fine again!
   LGTM! :)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb-nano] dsebastien commented on issue #252: scrubLog functionality can fail on JSON circular reference

Posted by GitBox <gi...@apache.org>.
dsebastien commented on issue #252:
URL: https://github.com/apache/couchdb-nano/issues/252#issuecomment-760499692


   It seems like I'm facing a variant of this issue.
   
   The following code works perfectly fine with v8.2.3:
   
   ```
     public ensureThatWorkspaceExists(workspaceId: string): Observable<boolean> {
       this.logger.debug(`Ensuring that the following workspace exists: ${workspaceId}`);
       return defer(() => from(this.databaseConnection.db.list())).pipe(  <----------- seems to crash here
         concatMap((databasesList) => {
               // never gets here
          ...
        }),
       );
     }
   ```
   
   In the closest `catchError`, I get the following error object:
   
   ```
   err = TypeError: Converting circular structure to JSON   --> starting at object with constructor 'Socket'    |    property 'parser' -> object with constructor 'HTTPParser' ....
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb-nano] Dryymoon commented on issue #252: scrubLog functionality can fail on JSON circular reference

Posted by GitBox <gi...@apache.org>.
Dryymoon commented on issue #252:
URL: https://github.com/apache/couchdb-nano/issues/252#issuecomment-781154445


   How to add custom agent:
   ```
   const agent = new http.Agent();
   agent.toJSON = () => null;
   const couchdb = require('nano')({
     url: 'http://admin:admin@localhost:5984',
     requestDefaults: {
       agent
     }
   });
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org