question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Non-deterministic recordings files

See original GitHub issue

Description

I’m not sure how to minimally reproduce this, but using persister-fs, I’m getting non-deterministic orderings of requests. Context: I’m working on making our polly recordings idempotent; e.g. scrubbing timestamps and auth tokens. I have everything idempotent now, but some recordings (not all) keep changing the order of requests; e.g.

[
  <recording for /auth/login>,
  <recording for /users>,
  <recording for /users/4>,
]

will get reordered as

[
  <recording for /users/4>,
  <recording for /auth/login>,
  <recording for /users>,
]

It seems like Persister uses stringify from fast-json-stable-stringify, which should produce a deterministic JSON blob, but Persister-FS re-parses the JSON string as JSON, which makes the JSON blob non-deterministic again:

https://github.com/Netflix/pollyjs/blob/8f86fb372b6ac3e6efa36a9dee07d81d8e112847/packages/@pollyjs/persister-fs/src/index.js#L31

I also don’t see a unit test for deterministic recordings?

https://github.com/Netflix/pollyjs/blob/master/packages/@pollyjs/persister-fs/tests/unit/persister-test.js

Shareable Source

Haven’t found a minimal repro yet

Error Message & Stack Trace

See description

Config

Copy the config used to setup the Polly instance:

const { setupPolly } = require('setup-polly-jest')
setupPolly({
  adapters: ['node-http'],
  persister: 'fs',
  logging: false,
  recordFailedRequests: true,
  recordIfMissing: true,
  mode: recordMode,
  matchRequestsBy: {
    headers: {
      exclude: ['Authorization'],
    },
  },
})

Dependencies

Copy the @pollyjs dependencies from package.json:

{
    "@pollyjs/adapter-fetch": "^2.6.3",
    "@pollyjs/adapter-node-http": "^2.6.3",
    "@pollyjs/core": "^2.6.3",
    "@pollyjs/persister-fs": "^2.6.3",
    "@pollyjs/persister-rest": "^2.6.3",
}

Relevant Links

Environment

  • Mac OS (darwin 18.7.0)
  • Yarn: 1.17.3
  • Node: v10.16.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
offirgolancommented, Oct 24, 2019

From the HAR 1.2 spec:

Sorting entries by startedDateTime (starting from the oldest) is preferred way how to export data since it can make importing faster.

See here

The sorting and deduping is done here: https://github.com/Netflix/pollyjs/blob/8f86fb372b6ac3e6efa36a9dee07d81d8e112847/packages/%40pollyjs/persister/src/har/log.js#L31-L45

Just as a note, Polly does depend on startedDateTime for features such as timing and expiration. Instead, maybe we can support a persister config option to disable sorting the entries.

0reactions
brandon-leapyearcommented, Mar 31, 2020

@pushred nope! our workaround has been working seamlessly for us (there are other idempotency problems, but this particular spot hasn’t given us any trouble)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Recording and Replaying. Computer programs are largely…
If we record how this non-determinism affects the program's behavior, we can replay the program from that recording and ensure it behaves ...
Read more >
MPL : Efficient Record/Replay of nondeterministic features of ...
and replay executions is very low with respect to the (nondeterministic) original execution while the size of the log files remains very small....
Read more >
WebReplayMechanics - WebKit Trac
Deterministic replay actually has two phases: record and replay. During recording, non-determinism is interposed and saved into a log by some ...
Read more >
Technical details — Undo.io
The Undo Engine records only non-deterministic data, which is sufficient for it to be able to recreate the program's entire memory and registers...
Read more >
OPR: Partial Deterministic Record and Replay for One-Sided ...
Deterministic Record and Replay (R&R) is an effective approach ... The naive implementation performs a log file write on each ac-.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found