bsave: attempt to catch and avoid jsdialogs during save.

No known test vector for this, but it may happen and we don't
want to hang saving with non-interactive interactive UI coming
from the bigsave process, that can't get events back.

If this happens - something is very odd, and we should disable
background save; so do that and try to clean-up in time.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Ifde2fe9ac8719321e38695725981b1f8b2b554f5
pull/9099/head
Michael Meeks 2024-05-18 16:45:14 +01:00
parent 6fc853c0f8
commit cf516d2ab1
2 changed files with 30 additions and 2 deletions

View File

@ -226,6 +226,26 @@ BgSaveChildWebSocketHandler::~BgSaveChildWebSocketHandler()
// Kit handler for messages from transient background save Kit
void BgSaveParentWebSocketHandler::terminateSave(const std::string &session, const std::string &reason)
{
LOG_WRN("terminating bgsave: " << reason);
// next time we get a non-background save.
_document->disableBgSave("on unexpected jsdialog");
// Hard terminate the bgsave child
sendMessage("exit");
shutdown(true, "unexpected jsdialog");
// Synthesize a failed save result
// FIXME: could this allow another new manual save to race against the ongoing bgsave ?
// either way - that's better than hanging and blocking if we get interactive dialogs on save.
std::string saveFailed = session + " unocommandresult: { \"commandName\": \".uno:Save\", \"success\": false }";
_document->sendFrame(saveFailed.c_str(), saveFailed.size(), WSOpCode::Text);
_document->updateModifiedOnFailedBgSave();
}
void BgSaveParentWebSocketHandler::handleMessage(const std::vector<char>& data)
{
LOG_DBG(_socketName << ": recv from parent [" <<
@ -233,8 +253,6 @@ void BgSaveParentWebSocketHandler::handleMessage(const std::vector<char>& data)
const StringVector tokens = StringVector::tokenize(data.data(), data.size());
// FIXME: check for badness - jsdialogs and so on and bail ... ?
// Should pass only:
// "error:", "forcedtracevent", "unocommandresult:"
// "statusindicator[start|finish|setvalue]"
@ -246,6 +264,13 @@ void BgSaveParentWebSocketHandler::handleMessage(const std::vector<char>& data)
return;
}
if (tokens[1] == "jsdialog:")
{
terminateSave(tokens[0], "Unexpected jsdialog message: " +
COOLProtocol::getAbbreviatedMessage(data));
return;
}
// Messages already include client-foo prefixes inherited from ourselves
_document->sendFrame(data.data(), data.size(), WSOpCode::Text);

View File

@ -108,4 +108,7 @@ public:
protected:
virtual void handleMessage(const std::vector<char>& data) override;
virtual void onDisconnect() override;
// something weird happened, cleanup & notify of failure
void terminateSave(const std::string &session, const std::string &reason);
};