From 6878e1065308caf0f79e380b4de1433ab1487a34 Mon Sep 17 00:00:00 2001
From: Erik Johnston <erik@matrix.org>
Date: Tue, 3 Aug 2021 13:29:17 +0100
Subject: [PATCH 1/7] Fix release script URL (#10516)

---
 changelog.d/10516.misc | 1 +
 scripts-dev/release.py | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
 create mode 100644 changelog.d/10516.misc

diff --git a/changelog.d/10516.misc b/changelog.d/10516.misc
new file mode 100644
index 0000000000..4d8c5e4805
--- /dev/null
+++ b/changelog.d/10516.misc
@@ -0,0 +1 @@
+Fix release script to open correct URL for the release.
diff --git a/scripts-dev/release.py b/scripts-dev/release.py
index e864dc6ed5..a339260c43 100755
--- a/scripts-dev/release.py
+++ b/scripts-dev/release.py
@@ -305,7 +305,7 @@ def tag(gh_token: Optional[str]):
     )
 
     # Open the release and the actions where we are building the assets.
-    click.launch(release.url)
+    click.launch(release.html_url)
     click.launch(
         f"https://github.com/matrix-org/synapse/actions?query=branch%3A{tag_name}"
     )

From 903db99ed552d06f0a9e0379e55e655c5761355b Mon Sep 17 00:00:00 2001
From: reivilibre <38398653+reivilibre@users.noreply.github.com>
Date: Tue, 3 Aug 2021 14:28:30 +0100
Subject: [PATCH 2/7] Fix PeriodicallyFlushingMemoryHandler inhibiting
 application shutdown (#10517)

---
 changelog.d/10517.bugfix    | 1 +
 synapse/logging/handlers.py | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 changelog.d/10517.bugfix

diff --git a/changelog.d/10517.bugfix b/changelog.d/10517.bugfix
new file mode 100644
index 0000000000..5b044bb34d
--- /dev/null
+++ b/changelog.d/10517.bugfix
@@ -0,0 +1 @@
+Fix the `PeriodicallyFlushingMemoryHandler` inhibiting application shutdown because of its background thread.
diff --git a/synapse/logging/handlers.py b/synapse/logging/handlers.py
index a6c212f300..af5fc407a8 100644
--- a/synapse/logging/handlers.py
+++ b/synapse/logging/handlers.py
@@ -45,6 +45,7 @@ class PeriodicallyFlushingMemoryHandler(MemoryHandler):
         self._flushing_thread: Thread = Thread(
             name="PeriodicallyFlushingMemoryHandler flushing thread",
             target=self._flush_periodically,
+            daemon=True,
         )
         self._flushing_thread.start()
 

From e8a3e8140291be0548ad80d0e942a9aaae6c2434 Mon Sep 17 00:00:00 2001
From: Brendan Abolivier <babolivier@matrix.org>
Date: Wed, 4 Aug 2021 16:13:24 +0200
Subject: [PATCH 3/7] Don't fail on empty bodies when sending out read receipts
 (#10531)

Fixes a bug introduced in rc1 that would cause Synapse to 400 on read receipts requests with empty bodies.

Broken in #10413
---
 changelog.d/10531.bugfix                 |  1 +
 synapse/rest/client/v2_alpha/receipts.py |  2 +-
 tests/rest/client/v2_alpha/test_sync.py  | 12 ++++++++++++
 3 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 changelog.d/10531.bugfix

diff --git a/changelog.d/10531.bugfix b/changelog.d/10531.bugfix
new file mode 100644
index 0000000000..aaa921ee91
--- /dev/null
+++ b/changelog.d/10531.bugfix
@@ -0,0 +1 @@
+Fix a bug introduced in Synapse v1.40.0rc1 that would cause Synapse to respond with an error when clients would update their read receipts.
diff --git a/synapse/rest/client/v2_alpha/receipts.py b/synapse/rest/client/v2_alpha/receipts.py
index 4b98979b47..d9ab836cd8 100644
--- a/synapse/rest/client/v2_alpha/receipts.py
+++ b/synapse/rest/client/v2_alpha/receipts.py
@@ -43,7 +43,7 @@ class ReceiptRestServlet(RestServlet):
         if receipt_type != "m.read":
             raise SynapseError(400, "Receipt type must be 'm.read'")
 
-        body = parse_json_object_from_request(request)
+        body = parse_json_object_from_request(request, allow_empty_body=True)
         hidden = body.get(ReadReceiptEventFields.MSC2285_HIDDEN, False)
 
         if not isinstance(hidden, bool):
diff --git a/tests/rest/client/v2_alpha/test_sync.py b/tests/rest/client/v2_alpha/test_sync.py
index f6ae9ae181..15748ed4fd 100644
--- a/tests/rest/client/v2_alpha/test_sync.py
+++ b/tests/rest/client/v2_alpha/test_sync.py
@@ -418,6 +418,18 @@ class ReadReceiptsTestCase(unittest.HomeserverTestCase):
         # Test that the first user can't see the other user's hidden read receipt
         self.assertEqual(self._get_read_receipt(), None)
 
+    def test_read_receipt_with_empty_body(self):
+        # Send a message as the first user
+        res = self.helper.send(self.room_id, body="hello", tok=self.tok)
+
+        # Send a read receipt for this message with an empty body
+        channel = self.make_request(
+            "POST",
+            "/rooms/%s/receipt/m.read/%s" % (self.room_id, res["event_id"]),
+            access_token=self.tok2,
+        )
+        self.assertEqual(channel.code, 200)
+
     def _get_read_receipt(self):
         """Syncs and returns the read receipt."""
 

From 02c2f631aed5cc2ef4bcaea25b443b625616f816 Mon Sep 17 00:00:00 2001
From: Brendan Abolivier <babolivier@matrix.org>
Date: Wed, 4 Aug 2021 17:09:27 +0100
Subject: [PATCH 4/7]  1.40.0rc2

---
 CHANGES.md               | 16 ++++++++++++++++
 changelog.d/10516.misc   |  1 -
 changelog.d/10517.bugfix |  1 -
 changelog.d/10531.bugfix |  1 -
 debian/changelog         |  6 ++++++
 synapse/__init__.py      |  2 +-
 6 files changed, 23 insertions(+), 4 deletions(-)
 delete mode 100644 changelog.d/10516.misc
 delete mode 100644 changelog.d/10517.bugfix
 delete mode 100644 changelog.d/10531.bugfix

diff --git a/CHANGES.md b/CHANGES.md
index 7ce28c4c18..75031986d3 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,3 +1,19 @@
+Synapse 1.40.0rc2 (2021-08-04)
+==============================
+
+Bugfixes
+--------
+
+- Fix the `PeriodicallyFlushingMemoryHandler` inhibiting application shutdown because of its background thread. ([\#10517](https://github.com/matrix-org/synapse/issues/10517))
+- Fix a bug introduced in Synapse v1.40.0rc1 that would cause Synapse to respond with an error when clients would update their read receipts. ([\#10531](https://github.com/matrix-org/synapse/issues/10531))
+
+
+Internal Changes
+----------------
+
+- Fix release script to open correct URL for the release. ([\#10516](https://github.com/matrix-org/synapse/issues/10516))
+
+
 Synapse 1.40.0rc1 (2021-08-03)
 ==============================
 
diff --git a/changelog.d/10516.misc b/changelog.d/10516.misc
deleted file mode 100644
index 4d8c5e4805..0000000000
--- a/changelog.d/10516.misc
+++ /dev/null
@@ -1 +0,0 @@
-Fix release script to open correct URL for the release.
diff --git a/changelog.d/10517.bugfix b/changelog.d/10517.bugfix
deleted file mode 100644
index 5b044bb34d..0000000000
--- a/changelog.d/10517.bugfix
+++ /dev/null
@@ -1 +0,0 @@
-Fix the `PeriodicallyFlushingMemoryHandler` inhibiting application shutdown because of its background thread.
diff --git a/changelog.d/10531.bugfix b/changelog.d/10531.bugfix
deleted file mode 100644
index aaa921ee91..0000000000
--- a/changelog.d/10531.bugfix
+++ /dev/null
@@ -1 +0,0 @@
-Fix a bug introduced in Synapse v1.40.0rc1 that would cause Synapse to respond with an error when clients would update their read receipts.
diff --git a/debian/changelog b/debian/changelog
index f0557c35ef..c523101f9a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+matrix-synapse-py3 (1.40.0~rc2) stable; urgency=medium
+
+  * New synapse release 1.40.0~rc2.
+
+ -- Synapse Packaging team <packages@matrix.org>  Wed, 04 Aug 2021 17:08:55 +0100
+
 matrix-synapse-py3 (1.40.0~rc1) stable; urgency=medium
 
   [ Richard van der Hoff ]
diff --git a/synapse/__init__.py b/synapse/__init__.py
index d6c1765508..da52463531 100644
--- a/synapse/__init__.py
+++ b/synapse/__init__.py
@@ -47,7 +47,7 @@ try:
 except ImportError:
     pass
 
-__version__ = "1.40.0rc1"
+__version__ = "1.40.0rc2"
 
 if bool(os.environ.get("SYNAPSE_TEST_PATCH_LOG_CONTEXTS", False)):
     # We import here so that we don't have to install a bunch of deps when

From 167335bd3da0fcfa0b2ba5ca3dc9d2f7c953c1eb Mon Sep 17 00:00:00 2001
From: Brendan Abolivier <babolivier@matrix.org>
Date: Wed, 4 Aug 2021 17:11:23 +0100
Subject: [PATCH 5/7] Fixup changelog

---
 CHANGES.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CHANGES.md b/CHANGES.md
index 75031986d3..052ab49599 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -5,7 +5,7 @@ Bugfixes
 --------
 
 - Fix the `PeriodicallyFlushingMemoryHandler` inhibiting application shutdown because of its background thread. ([\#10517](https://github.com/matrix-org/synapse/issues/10517))
-- Fix a bug introduced in Synapse v1.40.0rc1 that would cause Synapse to respond with an error when clients would update their read receipts. ([\#10531](https://github.com/matrix-org/synapse/issues/10531))
+- Fix a bug introduced in Synapse v1.40.0rc1 that could cause Synapse to respond with an error when clients would update their a receipts. ([\#10531](https://github.com/matrix-org/synapse/issues/10531))
 
 
 Internal Changes

From cc1cb0ab54654b1a1d938ae464a3471dd1b588a5 Mon Sep 17 00:00:00 2001
From: Brendan Abolivier <babolivier@matrix.org>
Date: Wed, 4 Aug 2021 17:14:55 +0100
Subject: [PATCH 6/7] Fixup changelog

---
 CHANGES.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CHANGES.md b/CHANGES.md
index 052ab49599..7d3bdebbde 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -5,7 +5,7 @@ Bugfixes
 --------
 
 - Fix the `PeriodicallyFlushingMemoryHandler` inhibiting application shutdown because of its background thread. ([\#10517](https://github.com/matrix-org/synapse/issues/10517))
-- Fix a bug introduced in Synapse v1.40.0rc1 that could cause Synapse to respond with an error when clients would update their a receipts. ([\#10531](https://github.com/matrix-org/synapse/issues/10531))
+- Fix a bug introduced in Synapse v1.40.0rc1 that could cause Synapse to respond with an error when clients would update read receipts. ([\#10531](https://github.com/matrix-org/synapse/issues/10531))
 
 
 Internal Changes

From 05111f8f26252cc936fce685846322289039128d Mon Sep 17 00:00:00 2001
From: Brendan Abolivier <babolivier@matrix.org>
Date: Wed, 4 Aug 2021 17:16:08 +0100
Subject: [PATCH 7/7] Fixup changelog

---
 CHANGES.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CHANGES.md b/CHANGES.md
index 7d3bdebbde..62ea684e58 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -11,7 +11,7 @@ Bugfixes
 Internal Changes
 ----------------
 
-- Fix release script to open correct URL for the release. ([\#10516](https://github.com/matrix-org/synapse/issues/10516))
+- Fix release script to open the correct URL for the release. ([\#10516](https://github.com/matrix-org/synapse/issues/10516))
 
 
 Synapse 1.40.0rc1 (2021-08-03)