Repository: matrix-org/synapse

Issue:
synapse.api.errors.StoreError: 404: No row found (pushers)
### Description

<!-- Describe here the problem that you are experiencing -->
Errors in synapse log:
```
    2019-04-26 13:17:52,980 - synapse.push.httppusher - 144 - ERROR - httppush.process-34525- Exception processing notifs 
    Traceback (most recent call last): 
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/synapse/push/httppusher.py", line 142, in _process
        yield self._unsafe_process()
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/internet/defer.py", line 1416, in _inlineCallbacks
        result = result.throwExceptionIntoGenerator(g)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/python/failure.py", line 491, in throwExceptionIntoGenerator
        return g.throw(self.type, self.value, self.tb)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/synapse/push/httppusher.py", line 178, in _unsafe_process
        self.clock.time_msec()
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/internet/defer.py", line 1416, in _inlineCallbacks
        result = result.throwExceptionIntoGenerator(g)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/python/failure.py", line 491, in throwExceptionIntoGenerator
        return g.throw(self.type, self.value, self.tb)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/synapse/storage/pusher.py", line 307, in update_pusher_last_stream_ordering_and_success
        desc="update_pusher_last_stream_ordering_and_success",
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/internet/defer.py", line 1416, in _inlineCallbacks
        result = result.throwExceptionIntoGenerator(g)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/python/failure.py", line 491, in throwExceptionIntoGenerator
        return g.throw(self.type, self.value, self.tb)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/synapse/storage/_base.py", line 393, in runInteraction
        *args, **kwargs
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/internet/defer.py", line 1416, in _inlineCallbacks
        result = result.throwExceptionIntoGenerator(g)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/python/failure.py", line 491, in throwExceptionIntoGenerator
        return g.throw(self.type, self.value, self.tb)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/synapse/storage/_base.py", line 442, in runWithConnection
        inner_func, *args, **kwargs
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/python/threadpool.py", line 250, in inContext
        result = inContext.theWork()
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/python/threadpool.py", line 266, in <lambda>
        inContext.theWork = lambda: context.call(ctx, func, *args, **kw)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/python/context.py", line 122, in callWithContext
        return self.currentContext().callWithContext(ctx, func, *args, **kw)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/python/context.py", line 85, in callWithContext
        return func(*args,**kw)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/enterprise/adbapi.py", line 306, in _runWithConnection
        compat.reraise(excValue, excTraceback)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/python/compat.py", line 464, in reraise
        raise exception.with_traceback(traceback)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/twisted/enterprise/adbapi.py", line 297, in _runWithConnection
        result = func(conn, *args, **kw)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/synapse/storage/_base.py", line 438, in inner_func
        return func(conn, *args, **kwargs)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/synapse/storage/_base.py", line 314, in _new_transaction
        r = func(txn, *args, **kwargs)
      File "/opt/venvs/matrix-synapse/lib/python3.5/site-packages/synapse/storage/_base.py", line 1031, in _simple_update_one_txn
        raise StoreError(404, "No row found (%s)" % (table,))
    synapse.api.errors.StoreError: 404: No row found (pushers)

```

### Version information

<!-- IMPORTANT: please answer the following questions, to help us narrow down the problem -->

<!-- Was this issue identified on matrix.org or another homeserver? -->
- **Homeserver**: 

If not matrix.org:

<!--
What version of Synapse is running?
You can find the Synapse version by inspecting the server headers (replace matrix.org with
your own homeserver domain):
$ curl -v https://matrix.org/_matrix/client/versions 2>&1 | grep "Server:"
-->
- **Version**: 
```
Server: nginx/1.10.3
ii  matrix-synapse                  0.34.0.1-0matrix2              all          transitional package
ii  matrix-synapse-py3              0.99.1.1+stretch1              amd64        Open federated Instant Messaging and VoIP server
ii  python-daemonize                2.3.1-0matrix1                 all          Library to enable your code run as a daemon process on Unix-
ii  python-frozendict               0.4-0matrix1                   all          An immutable dictionary
ii  python-phonenumbers             8.4.0~matrix~jessie1           all          Python port of Google libphonenumber
ii  python-pydenticon               0.2-0matrix1                   all          Library for generating identicons. Port of Sigil

```
- **Install method**: 
<!-- examples: package manager/git clone/pip  -->
deb
- **Platform**: 
<!--
Tell us about the environment in which your homeserver is operating
distro, hardware, if it's running in a vm/container, etc.
-->
Debian 9.8


Discussion:
Is this an ongoing issue? Is it causing problems other than the stacktrace?

(I can imagine it might happen occasionally when a pusher gets deleted)
> Is this an ongoing issue?

This is occur again twice at 2019-05-01. 

> Is it causing problems other than the stacktrace?

I don't know. May be some user on server have problem with it, but do not said me.

Time to time I check ERROR's in synapse logs. And try understand what is happen...

I have the same issue on synapse v1.0.0
Is there anyone have the solution for it.
synapse.api.errors.StoreError: 404: No row found (pushers)
@progserega 
Have you try to change the DEFAULT_PUSHER_UR 
in this file

https://github.com/vector-im/riot-android/blob/047e156cc7f3c708fdcdb4e90c0df63155076bae/vector/src/main/java/im/vector/push/PushManager.java
> @progserega
> Have you try to change the DEFAULT_PUSHER_UR
> in this file
> 
> https://github.com/vector-im/riot-android/blob/047e156cc7f3c708fdcdb4e90c0df63155076bae/vector/src/main/java/im/vector/push/PushManager.java

You mean, that I need get sources of riot-android, patch it, build and try this version of client?

Resolving patch:
diff --git a/synapse/storage/databases/main/pusher.py b/synapse/storage/databases/main/pusher.py
--- a/synapse/storage/databases/main/pusher.py
+++ b/synapse/storage/databases/main/pusher.py
@@ -344,7 +344,9 @@ def delete_pusher_txn(txn, stream_id):
                 txn, self.get_if_user_has_pusher, (user_id,)
             )
 
-            self.db_pool.simple_delete_one_txn(
+            # It is expected that there is exactly one pusher to delete, but
+            # if it isn't there (or there are multiple) delete them all.
+            self.db_pool.simple_delete_txn(
                 txn,
                 "pushers",
                 {"app_id": app_id, "pushkey": pushkey, "user_name": user_id},


Test patch: