Closed NGEfreak closed 5 years ago
Could it be this line that needs improvements? https://github.com/jhthorsen/json-validator/blob/master/lib/JSON/Validator.pm#L485
Yes, that line is part of the problem. I have attached some files with an example.
good.txt contains a debug report of a successful validation. bad.txt contains the debug report of the failed validation. Both are from the same process.
method_calls.txt lists all _validate()
calls of the bad run. Each segment shows @_
(without invocant) and $seen_addr
.
As you can see the memory address 94152271142056 of $schema
is the same in call 10 and 20. Of course, the content of $schema
is different in both calls. This means that the reference of call 10 gets destroyed and the memory address is set free again. Later, the memory address is reused again during call 20.
I hope 2.19 fixes this issue. I've added random-errors.t
which reflects the test case you created above.
I have a schema with several
type => ['string', 'null']
constraints that randomly fail with valid data.Here is an example script:
For example, running this script 20 times I got this result:
It doesn't matter if I move the JSON::Validator initialization outside the for-loop.
I have also tried some simpler schemas:
Since this problem is really strange and perhaps related to my Perl installation I have also run this code on some other machines. However, the problem occurs on all of them:
I have also tried several older versions but with no difference:
EDIT: Just tried it on Red Hat with Perl 5.16.3 and it looks like it works! Perhaps hash order randomization (since 5.18.x) is the cause of the problem?