html_url,issue_url,id,node_id,user,user_label,created_at,updated_at,author_association,body,reactions,issue,issue_label,performed_via_github_app https://github.com/simonw/datasette/issues/935#issuecomment-674450607,https://api.github.com/repos/simonw/datasette/issues/935,674450607,MDEyOklzc3VlQ29tbWVudDY3NDQ1MDYwNw==,9599,simonw,2020-08-15T21:50:41Z,2020-08-15T21:50:41Z,OWNER,"The bug is here: https://github.com/simonw/datasette/blob/13b3b51087964d5e1a8c1cdd2495e07bdbe176b8/datasette/database.py#L89-L100 If `conn = self.connect(write=True)` raises an exception the entire server hangs, like this: ``` % datasette -i fixtures.db --get / Exception in thread Thread-1: Traceback (most recent call last): File ""/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py"", line 932, in _bootstrap_inner self.run() File ""/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py"", line 870, in run self._target(*self._args, **self._kwargs) File ""/Users/simon/.local/share/virtualenvs/latest-datasette-with-all-plugins-PJL_Xy9e/lib/python3.8/site-packages/datasette/database.py"", line 92, in _execute_writes conn = self.connect(write=True) File ""/Users/simon/.local/share/virtualenvs/latest-datasette-with-all-plugins-PJL_Xy9e/lib/python3.8/site-packages/datasette/database.py"", line 55, in connect assert not (write and not self.is_mutable) AssertionError ... server hangs here ... ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",679646710,"db.execute_write_fn(create_tables, block=True) hangs a thread if connection fails", https://github.com/simonw/datasette/issues/935#issuecomment-674450652,https://api.github.com/repos/simonw/datasette/issues/935,674450652,MDEyOklzc3VlQ29tbWVudDY3NDQ1MDY1Mg==,9599,simonw,2020-08-15T21:51:22Z,2020-08-15T21:51:22Z,OWNER,"The easiest way to recreate this is to attempt a write against an immutable database, which triggers this assertion error: https://github.com/simonw/datasette/blob/13b3b51087964d5e1a8c1cdd2495e07bdbe176b8/datasette/database.py#L47-L55","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",679646710,"db.execute_write_fn(create_tables, block=True) hangs a thread if connection fails", https://github.com/simonw/datasette/issues/935#issuecomment-674451012,https://api.github.com/repos/simonw/datasette/issues/935,674451012,MDEyOklzc3VlQ29tbWVudDY3NDQ1MTAxMg==,9599,simonw,2020-08-15T21:56:13Z,2020-08-15T21:56:13Z,OWNER,"This implementation seems to fix it, need to work out how to test though. ```diff diff --git a/datasette/database.py b/datasette/database.py index ffa7a79..7ba1456 100644 --- a/datasette/database.py +++ b/datasette/database.py @@ -89,14 +89,22 @@ class Database: def _execute_writes(self): # Infinite looping thread that protects the single write connection # to this database - conn = self.connect(write=True) + conn_exception = None + conn = None + try: + conn = self.connect(write=True) + except Exception as e: + conn_exception = e while True: task = self._write_queue.get() - try: - result = task.fn(conn) - except Exception as e: - print(e) - result = e + if conn_exception is not None: + result = conn_exception + else: + try: + result = task.fn(conn) + except Exception as e: + print(e) + result = e task.reply_queue.sync_q.put(result) async def execute_fn(self, fn): ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",679646710,"db.execute_write_fn(create_tables, block=True) hangs a thread if connection fails", https://github.com/simonw/datasette/pull/936#issuecomment-674453318,https://api.github.com/repos/simonw/datasette/issues/936,674453318,MDEyOklzc3VlQ29tbWVudDY3NDQ1MzMxOA==,9599,simonw,2020-08-15T22:29:15Z,2020-08-15T22:32:58Z,OWNER,"Test failure: ``` tests/test_canned_queries.py F >>> captured stdout >>> __enter__ >>> traceback >>> canned_write_client = def test_insert(canned_write_client): response = canned_write_client.post( ""/data/add_name"", {""name"": ""Hello""}, allow_redirects=False, csrftoken_from=True, cookies={""foo"": ""bar""}, ) assert 302 == response.status > assert ""/data/add_name?success"" == response.headers[""Location""] E AssertionError: assert '/data/add_name?success' == '/data/add_name' E - /data/add_name E + /data/add_name?success E ? ++++++++ /Users/simon/Dropbox/Development/datasette/tests/test_canned_queries.py:66: AssertionError ``` No idea why this change would affect that test.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",679650632,Don't hang in db.execute_write_fn() if connection fails, https://github.com/simonw/datasette/pull/936#issuecomment-674453772,https://api.github.com/repos/simonw/datasette/issues/936,674453772,MDEyOklzc3VlQ29tbWVudDY3NDQ1Mzc3Mg==,22429695,codecov[bot],2020-08-15T22:35:29Z,2020-08-15T22:35:29Z,NONE,"# [Codecov](https://codecov.io/gh/simonw/datasette/pull/936?src=pr&el=h1) Report > Merging [#936](https://codecov.io/gh/simonw/datasette/pull/936?src=pr&el=desc) into [main](https://codecov.io/gh/simonw/datasette/commit/13b3b51087964d5e1a8c1cdd2495e07bdbe176b8&el=desc) will **increase** coverage by `0.02%`. > The diff coverage is `n/a`. [![Impacted file tree graph](https://codecov.io/gh/simonw/datasette/pull/936/graphs/tree.svg?width=650&height=150&src=pr&token=eSahVY7kw1)](https://codecov.io/gh/simonw/datasette/pull/936?src=pr&el=tree) ```diff @@ Coverage Diff @@ ## main #936 +/- ## ========================================== + Coverage 84.02% 84.04% +0.02% ========================================== Files 28 28 Lines 3774 3774 ========================================== + Hits 3171 3172 +1 + Misses 603 602 -1 ``` | [Impacted Files](https://codecov.io/gh/simonw/datasette/pull/936?src=pr&el=tree) | Coverage Δ | | |---|---|---| | [datasette/app.py](https://codecov.io/gh/simonw/datasette/pull/936/diff?src=pr&el=tree#diff-ZGF0YXNldHRlL2FwcC5weQ==) | `96.18% <0.00%> (+0.18%)` | :arrow_up: | ------ [Continue to review full report at Codecov](https://codecov.io/gh/simonw/datasette/pull/936?src=pr&el=continue). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://codecov.io/gh/simonw/datasette/pull/936?src=pr&el=footer). Last update [13b3b51...94a68b9](https://codecov.io/gh/simonw/datasette/pull/936?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments). ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",679650632,Don't hang in db.execute_write_fn() if connection fails,