Skip to content

journalctl silently suppresses valid duplicate log messages #14898

Closed

Description

@georgmu

systemd version the issue has been seen with

243

Used distribution

Fedora 31

Expected behaviour you didn't see

I have a program which should print a hex dump to stderr - resulting in the output shown in the journal. I have created a demo program here: https://gist.github.com/georgmu/7178426db59813e108e0d29b77b84c31 .
I run the program with systemd-run --user ./hextest 0 The expeceted behavoir is to always show all lines of the hex dump.
When running with argument 1, 2 or 3 (1 or 3 increases the byte in the hexdump , 2 or 3 print the offset in the first column), the lines are not the same and all lines are printed in the journal.

When run without systemd-run, I get the complete output to stderr:

starting...

hex dump of 512 bytes:
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 
06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................ 

Exiting...

Unexpected behaviour you saw

journalctl --user only shows some lines if the lines are the same (hextest run in mode 0). The number of lines shown is not stable. Sometimes there are 2-4 lines, sometimes 10 lines:

Feb 18 11:58:18 nb-georg hextest[527768]: starting...
Feb 18 11:58:18 nb-georg hextest[527768]: hex dump of 512 bytes:
Feb 18 11:58:18 nb-georg hextest[527768]: 06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................
Feb 18 11:58:18 nb-georg hextest[527768]: 06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................
Feb 18 11:58:18 nb-georg hextest[527768]: Exiting...

The output of the hex dump should always be 32 lines long.

Activity

  1. georgmu commented on Feb 19, 2020

    @georgmu
    ContributorAuthor

    When checking output with journalctl --user -o verbose, I can see that the sequence numbers increase, so the initial log record seems to be generated.

    ... ;i=7a276; ...
            MESSAGE=starting...
    ... ;i=7a277; ...
            MESSAGE=hex dump of 512 bytes:
    ... ;i=7a278; ...
            MESSAGE=06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................
    ... ;i=7a286; ...
            MESSAGE=06 06 06 06 06 06 06 06  06 06 06 06 06 06 06 06  |  ................
    ... ;i=7a298; ...
            MESSAGE=Exiting...
    

    0x7a298 - 0x7a276 + 1 = 35, which is the expected number of log records (32 dump lines + 3 extra lines)

  2. georgmu commented on Feb 19, 2020

    @georgmu
    ContributorAuthor

    The problem seems to be that all records are equal AND the timestamps are also equal. I modified the test-journal-stream.c to only add the same number (NUMBER=1 instead of NUMBER=i) and to keep the journals (commented the rm_rf call at the end). When the times increase, everything is fine. If the times stay the same (move the dual_timestamp_get() out of the loop), only the first equal entry is added (as seen by the serial numbers in the verbose output).

    Now when the read() reads multiple lines at once, which are splitted afterwards, all these lines seem to be added with the same time and the entry is not added at all.

  3. georgmu commented on Feb 19, 2020

    @georgmu
    ContributorAuthor

    The problem is not in writing, but in reading the journal. The journal contains the record (checked comparing hexdumps of the journal).

    The problem is in function next_beyond_location(). The function compare_with_location() returns 0 for the duplicate record. The comment above this section states:

    /* OK, we found the spot, now let's advance until an entry
     * that is actually different from what we were previously
     * looking at. This is necessary to handle entries which exist
     * in two (or more) journal files, and which shall all be
     * suppressed but one. */
    

    Well. Here we have two (validly equal) entries in the same journal file.

    Hard-coding found to true here solves it (duplicate entries are printed), but this is not the real solution here.

    Maybe it is possible to check if the entries are from the same or different journals?

  4. changed the title [-]journald silently suppresses duplicate log messages[/-] [+]journalctl silently suppresses valid duplicate log messages[/+] on Feb 19, 2020
  5. mrc0mmand commented on Mar 18, 2020

    @mrc0mmand
    Member

    Resolved by #14913.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions