MCPcopy Create free account
hub / github.com/coder/coder / drainToEOF

Method drainToEOF

coderd/x/chatd/chatdebug/transport.go:413–437  ·  view source on GitHub ↗

64 KB

()

Source from the content-addressed store, hash-verified

411const maxDrainBytes = 64 * 1024 // 64 KB
412
413func (r *recordingBody) drainToEOF() error {
414 buf := make([]byte, 4*1024)
415 var drained int64
416 for {
417 n, err := r.inner.Read(buf)
418
419 r.mu.Lock()
420 r.accumulateReadLocked(buf, n, err)
421 drained += int64(n)
422 r.mu.Unlock()
423
424 if err != nil {
425 if errors.Is(err, io.EOF) {
426 return nil
427 }
428 return err
429 }
430
431 // Safety valve: stop draining after maxDrainBytes to prevent
432 // Close() from blocking indefinitely on a chunked body.
433 if drained >= maxDrainBytes {
434 return io.ErrUnexpectedEOF
435 }
436 }
437}
438
439func isCompleteUnknownLengthJSONBody(contentType string, body []byte) bool {
440 if !isJSONLikeContentType(contentType) {

Callers 1

CloseMethod · 0.95

Calls 5

accumulateReadLockedMethod · 0.95
ReadMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
IsMethod · 0.45

Tested by

no test coverage detected