Skip to content

Fix inverted write() error check in profile exporter#501

Closed
xroche wants to merge 1 commit into
DataDog:mainfrom
algolia:fix/exporter-write-error-check
Closed

Fix inverted write() error check in profile exporter#501
xroche wants to merge 1 commit into
DataDog:mainfrom
algolia:fix/exporter-write-error-check

Conversation

@xroche

@xroche xroche commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fix write_profile() in src/exporter/ddprof_exporter.cc which checked write() == 0 instead of write() < 0.

write() returns -1 on error, not 0. The previous check:

  • Missed all real errors (ENOSPC, EIO, EPIPE) — returned success when the write failed
  • False-alarmed on legitimate 0-byte writes — returned error when nothing was wrong

The fix also handles short writes with a loop, since write() may return less than the requested length.

Motivation

Profile data was silently lost on disk errors, causing invisible profiling gaps with no diagnostic signal.

How to test the change?

Write to a full filesystem or a closed pipe — the error should now be detected and reported instead of silently ignored.

Classification

  • CWE-253: Incorrect Check of Function Return Value

Fixes #498

write() returns -1 on error, not 0. The previous check:
- Missed all real errors (ENOSPC, EIO, EPIPE)
- False-alarmed on legitimate 0-byte writes

Also handle short writes with a loop, since write() may return
less than the requested length.

Fixes DataDog#498
@xroche
xroche marked this pull request as ready for review February 27, 2026 20:12
@r1viollet

Copy link
Copy Markdown
Collaborator
[ 93%] Building CXX object CMakeFiles/ddprof.dir/src/jit/jitdump.cc.o
/go/src/github.com/DataDog/apm-reliability/ddprof-build/ddprof/src/exporter/ddprof_exporter.cc:64:3: error: 'auto ptr' can be declared as 'const auto *ptr' [readability-qualified-auto,-warnings-as-errors]
   64 |   auto ptr = buffer->ptr;
      |   ^~~~
      |   const auto *
141713 warnings generated.
Suppressed 141747 warnings (141712 in non-user code, 35 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
1 warning treated as error
make[2]: *** [CMakeFiles/ddprof.dir/build.make:975: CMakeFiles/ddprof.dir/src/exporter/ddprof_exporter.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:[1366](https://gitlab.ddbuild.io/DataDog/apm-reliability/ddprof-build/-/jobs/1471174917#L1366): CMakeFiles/ddprof.dir/all] Error 2

Minor linter fix required

@r1viollet

Copy link
Copy Markdown
Collaborator

closing in favour of #507

@r1viollet r1viollet closed this Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

write() error check inverted in profile exporter

2 participants