From bc945d81e6f0ae76738fc70925daa1243b159af7 Mon Sep 17 00:00:00 2001 From: nezuo Date: Tue, 9 Apr 2024 11:28:36 -0700 Subject: [PATCH 1/3] Fix infinite yield in BindToClose when a document fails to load --- src/Collection.lua | 1 + src/init.test.lua | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Collection.lua b/src/Collection.lua index c520a66..676f069 100644 --- a/src/Collection.lua +++ b/src/Collection.lua @@ -120,6 +120,7 @@ function Collection:load(key, defaultUserIds) :finally(function(status) if status ~= Promise.Status.Resolved then self.openDocuments[key] = nil + self.autoSave.ongoingLoads -= 1 end end) end diff --git a/src/init.test.lua b/src/init.test.lua index 930ee9a..bc430ac 100644 --- a/src/init.test.lua +++ b/src/init.test.lua @@ -390,5 +390,21 @@ return function(x) assert(coroutine.status(thread) == "dead", "") end) + + x.test("BindToClose should finish if a document fails to load", function(context) + local collection = context.lapis.createCollection("collection", DEFAULT_OPTIONS) + + context.write("collection", "document", "INVALID DATA") + collection:load("document"):catch(function() end) + + -- Wait to close game so that the save request doesn't get cancelled. + task.wait(0.1) + + Promise.try(function() + context.lapis.autoSave:onGameClose() + end) + :timeout(1) + :expect() + end) end) end From d74a8e462ba0fe8ce9571c207e24ef13b00a8763 Mon Sep 17 00:00:00 2001 From: nezuo Date: Tue, 9 Apr 2024 11:30:29 -0700 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c75dd6a..8abf779 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Lapis Changelog ## Unreleased Changes +* Fix infinite iyeld in `game:BindToClose` when a document failed to load. ([#45]) + +[#45]: https://github.com/nezuo/lapis/pull/45 ## 0.2.10 - March 25, 2024 * `Document:load` now infinitely yields and doesn't load the document after `game:BindToClose` is called. If a document From bbb79b492e4fc31c7d5d449ec957f4de77aeae82 Mon Sep 17 00:00:00 2001 From: nezuo Date: Tue, 9 Apr 2024 11:31:23 -0700 Subject: [PATCH 3/3] Fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8abf779..efb88b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Lapis Changelog ## Unreleased Changes -* Fix infinite iyeld in `game:BindToClose` when a document failed to load. ([#45]) +* Fix infinite yield in `game:BindToClose` caused by a document failing to load. ([#45]) [#45]: https://github.com/nezuo/lapis/pull/45