Skip to content

Commit

Permalink
Fix shutdown in --console mode (#14621)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteemann committed Aug 17, 2021
1 parent 0bff56b commit 5eaf1d2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
devel
-----

* Send a keystroke to arangod's stdin when a shutdown command is received via
the REST API `/_admin/shutdown` and the server is started with the
`--console` argument. The keystroke will exit the blocking read loop that
is waiting on console input and that otherwise blocks the shutdown.
The implementation is based on ioctl and is thus only present on Linux and
MacOS.

* Some AQL queries erroneously reported the "access after data-modification"
error for queries in which there was a read attempt from a collection
_before_ a data-modification operation. Such access is legal and should not
Expand All @@ -21,7 +28,7 @@ devel
"DATASOURCE_NOT_FOUND". This is now fixed to "BAD_PARAMETER"
to emphasize that the collection is fine but the input is invalid.

* Fixed: _api/transaction/begin called on edge collections of disjoint
* Fixed: /_api/transaction/begin called on edge collections of disjoint
SmartGraphs falsely returned CollectionNotFound errors.

* Bugfix: In more complex queries there was a code-path where a (Disjoint-)
Expand Down
30 changes: 27 additions & 3 deletions arangod/RestServer/ConsoleFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ConsoleFeature.h"

#include "ApplicationFeatures/ApplicationServer.h"
#include "Basics/debugging.h"
#include "Basics/messages.h"
#include "FeaturePhases/AgencyFeaturePhase.h"
#include "Logger/LogMacros.h"
Expand All @@ -39,15 +40,19 @@

#include <iostream>

#ifndef _WIN32
#include <sys/ioctl.h>
#include <unistd.h>
#endif

using namespace arangodb::application_features;
using namespace arangodb::options;

namespace arangodb {

ConsoleFeature::ConsoleFeature(application_features::ApplicationServer& server)
: ApplicationFeature(server, "Console"),
_operationMode(OperationMode::MODE_SERVER),
_consoleThread(nullptr) {
_operationMode(OperationMode::MODE_SERVER) {
startsAfter<AgencyFeaturePhase>();
}

Expand All @@ -65,10 +70,29 @@ void ConsoleFeature::start() {
auto& sysDbFeature = server().getFeature<arangodb::SystemDatabaseFeature>();
auto database = sysDbFeature.use();

_consoleThread.reset(new ConsoleThread(server(), database.get()));
_consoleThread = std::make_unique<ConsoleThread>(server(), database.get());
_consoleThread->start();
}

void ConsoleFeature::beginShutdown() {
if (_operationMode != OperationMode::MODE_CONSOLE) {
return;
}

TRI_ASSERT(_consoleThread != nullptr);

_consoleThread->userAbort();

#ifndef _WIN32
if (isatty(STDIN_FILENO)) {
char c = '\n';
// send ourselves a character, so that we can get out of the blocking
// linenoise function that reads a character from the terminal
[[maybe_unused]] int res = ioctl(STDIN_FILENO, TIOCSTI, &c);
}
#endif
}

void ConsoleFeature::unprepare() {
if (_operationMode != OperationMode::MODE_CONSOLE) {
return;
Expand Down
3 changes: 3 additions & 0 deletions arangod/RestServer/ConsoleFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@
#include "GeneralServer/OperationMode.h"
#include "RestServer/ConsoleThread.h"

#include <memory>

namespace arangodb {

class ConsoleFeature final : public application_features::ApplicationFeature {
public:
explicit ConsoleFeature(application_features::ApplicationServer& server);

void start() override final;
void beginShutdown() override final;
void unprepare() override final;

private:
Expand Down

0 comments on commit 5eaf1d2

Please sign in to comment.