youknowone / itunes-iap

Apple iTunes In-app purchase verification tool
http://itunes-iap.readthedocs.io
Other
136 stars 50 forks source link

IndexError when exiting context manager #52

Open maccinza opened 6 years ago

maccinza commented 6 years ago

I'm experiencing a similar IndexError in one of my api views when using itunesiap.env.sandbox context manager:

# ...
if sandbox:
    with itunesiap.env.sandbox:
        try:
            response = itunesiap.verify(raw_data, use_sandbox=True)
            return True, response
        except (ItunesServerNotAvailable, ItunesServerNotReachable):
            no_response = True
        except itunesiap.exc.InvalidReceipt as exc:
            error = exc.description

Sentry actually indicates the error/exception being raised when exiting the contextmanager:

itunesiap/environment.py in __exit__ at line 42
        self._ctx_id = len(self._stack)
        self.push()
        return self
    def __exit__(self, exc_type, exc_value, tb):
        self._stack.pop(self._ctx_id)  # this line

Any clues on what might be happening?

youknowone commented 6 years ago

Are you using multi-threaded or any async logics? itunesiap's context manager implementation is not safe for async jobs. env param will help your problem. (You need recent version of itunesiap)

itunesiap.verify(raw_data, env=itunesiap.env.review)