New submission from Phil Frost <phil.fr...@postmates.com>:

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.

----------
components: Interpreter Core
files: decimal.py
messages: 344772
nosy: Phil Frost
priority: normal
severity: normal
status: open
title: Decimal divisions sometimes 10x or 100x too large
versions: Python 2.7
Added file: https://bugs.python.org/file48396/decimal.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37168>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to