File tree Expand file tree Collapse file tree 3 files changed +18
-0
lines changed
src/integrations/terminal Expand file tree Collapse file tree 3 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,20 @@ export abstract class BaseTerminalProcess extends EventEmitter<RooTerminalProces
137137 */
138138 abstract getUnretrievedOutput ( ) : string
139139
140+ /**
141+ * Trims already retrieved content from the internal output buffer.
142+ *
143+ * This prevents unbounded memory growth when processing large
144+ * command outputs by discarding data that has already been
145+ * consumed by callers of `getUnretrievedOutput`.
146+ */
147+ protected trimRetrievedOutput ( ) : void {
148+ if ( this . lastRetrievedIndex > 0 ) {
149+ this . fullOutput = this . fullOutput . slice ( this . lastRetrievedIndex )
150+ this . lastRetrievedIndex = 0
151+ }
152+ }
153+
140154 protected startHotTimer ( data : string ) {
141155 this . isHot = true
142156
Original file line number Diff line number Diff line change @@ -146,6 +146,8 @@ export class ExecaTerminalProcess extends BaseTerminalProcess {
146146 this . emitRemainingBufferIfListening ( )
147147 this . stopHotTimer ( )
148148 this . emit ( "completed" , this . fullOutput )
149+ this . lastRetrievedIndex = this . fullOutput . length
150+ this . trimRetrievedOutput ( )
149151 this . emit ( "continue" )
150152 this . subprocess = undefined
151153 }
Original file line number Diff line number Diff line change @@ -254,6 +254,8 @@ export class TerminalProcess extends BaseTerminalProcess {
254254 // so that api request stalls to let diagnostics catch up").
255255 this . stopHotTimer ( )
256256 this . emit ( "completed" , this . removeEscapeSequences ( this . fullOutput ) )
257+ this . lastRetrievedIndex = this . fullOutput . length
258+ this . trimRetrievedOutput ( )
257259 this . emit ( "continue" )
258260 }
259261
You can’t perform that action at this time.
0 commit comments