Author Phil Frost
Recipients Phil Frost
Date 2019-06-05.22:05:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1559772321.45.0.42770583159.issue37168@roundup.psfhosted.org>
In-reply-to
Content
We've observed instances of Decimal divisions being incorrect a few times per day in a web application serving millions of requests daily. I've been unable to reproduce the issue but have been investigating core dumps which suggest either some issue in the C Python implementation or its execution environment.

Python 2.7.15 on Alpine Linux Docker containers.

A slightly modified decimal.py is attached. It's been modified to check that the answer is approximately correct and dumps core if not. It also has a few local variables added to provide additional insight. I've annotated the file with values from the core dump and my reasoning about what should happen.

The crux of the problem is the loop at line 1389. There are 3 ways to determine how many times this loop executed:

1. the number of zeros removed from coeff
2. the number of times exp is incremented
3. the number of times division_counter is incremented

Oddly, #1 and #3 indicate the loop happened 27 times, while #2 indicates the loop happened 28 times.

One possible explanation (which makes about as much sense as any other) is that `exp += 1` sometimes adds 2 instead of 1. This means the loop happens 1 time fewer than it should, leaving `coeff` 10 times bigger than it should properly be. Or (very rarely) this happens twice and the result is 100 times bigger.

I find it very odd that something as basic as `+= 1` should not work, but at the moment it is the best explanation I have.

Unfortunately I can't share the core dump, as I've only been able to observe the issue in production so the core contains private information. But I'd welcome any ideas for further exploration. Or perhaps someone is aware of an existing bug that would explain this behavior.
History
Date User Action Args
2019-06-05 22:05:21Phil Frostsetrecipients: + Phil Frost
2019-06-05 22:05:21Phil Frostsetmessageid: <1559772321.45.0.42770583159.issue37168@roundup.psfhosted.org>
2019-06-05 22:05:21Phil Frostlinkissue37168 messages
2019-06-05 22:05:21Phil Frostcreate