Skip to content

process.stdout cannot be JSON.stringify()ed because of circular dependency #31277

@nazarhussain

Description

@nazarhussain
  • Version: v12.14.1
  • Platform: Darwin Kernel Version 19.2.0
  • Subsystem: Streams

There are some change introduced in 12.14.1 in process.stdout which created a circular dependency. This behaviour is not detected in 12.14.0, and can't find any reference for changes
in published change log.

Here is the simple code to reproduce the issue in 12.14.1

➜  nvm use 12.14.1
➜  node -i
Welcome to Node.js v12.14.1.
Type ".help" for more information.
> JSON.stringify(process.stdout)
Thrown:
TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'WriteStream'
    |     property '_writableState' -> object with constructor 'WritableState'
    |     property 'afterWriteTickInfo' -> object with constructor 'Object'
    --- property 'stream' closes the circle
    at JSON.stringify (<anonymous>)
>

It works well with 12.14.0

➜  nvm use 12.14.0
➜  node -i
Welcome to Node.js v12.14.0.
Type ".help" for more information.
> JSON.stringify(process.stdout)
'{"connecting":false,"_hadError":false,"_parent":null,"_host":null,"_readableState":{"objectMode":false,"highWaterMark":16384,"buffer":{"head":null,"tail":null,"length":0},"length":0,"pipes":null,"pipesCount":0,"flowing":null,"ended":false,"endEmitted":false,"reading":false,"sync":true,"needReadable":false,"emittedReadable":false,"readableListening":false,"resumeScheduled":false,"paused":true,"emitClose":false,"autoDestroy":false,"destroyed":false,"defaultEncoding":"utf8","awaitDrain":0,"readingMore":false,"decoder":null,"encoding":null},"readable":false,"_events":{},"_eventsCount":3,"_writableState":{"objectMode":false,"highWaterMark":16384,"finalCalled":false,"needDrain":false,"ending":false,"ended":false,"finished":false,"destroyed":false,"decodeStrings":false,"defaultEncoding":"utf8","length":0,"writing":false,"corked":0,"sync":false,"bufferProcessing":false,"writecb":null,"writelen":0,"bufferedRequest":null,"lastBufferedRequest":null,"pendingcb":1,"prefinished":false,"errorEmitted":false,"emitClose":false,"autoDestroy":false,"bufferedRequestCount":0,"corkedRequestsFree":{"next":null,"entry":null}},"writable":true,"allowHalfOpen":false,"_sockname":null,"_pendingData":null,"_pendingEncoding":"","server":null,"_server":null,"columns":210,"rows":80,"_type":"tty","fd":1,"_isStdio":true}'
>

I don't know if it's a bug or an explicit change made in interface. If its known change, then must be reported to the change log.

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions