Skip to content

SQLChannel does not create directory for absolute paths #5182

@daym

Description

@daym

SQLChannel::setProperty() in Data/src/SQLChannel.cpp only creates the log directory when the path is relative:

  else if (name == "directory")
  {
      std::string dir = value;

      if (!Path(File(dir).path()).isAbsolute())
      {
          Path d(dir);
          dir = d.makeDirectory().makeAbsolute().toString();
          File f(dir);
          if (!f.exists()) f.createDirectories();
      }

      _directory = dir;
  }

When no directory is explicitly set, SQLChannel uses Path::tempHome() as the default, which returns an absolute path (~/.local/tmp/ on Linux). Since this path is absolute, the createDirectories() call is skipped.

Consequence:

If ~/.local/tmp/ does not exist (which is common—it's a non-standard path that most systems don't create by default):

  1. FileChannel::open() fails with ENOENT when trying to write to ~/.local/tmp/*.log.sql
  2. SQLChannel attempts to log this failure back into its own message queue
  3. The background worker thread tries to flush this message, fails again, logs again--never draining the queue
  4. SQLChannel::stop() waits indefinitely for the worker thread to finish
  5. The program hangs

To Reproduce

  1. Run the DataTest::testSQLChannel test in an environment where $HOME/.local/tmp/ does not exist.
  2. It hangs.

Suggested fix:

Remove the isAbsolute() check so that directories are created regardless of whether the path is relative or absolute:

  else if (name == "directory")
  {
      std::string dir = value;

      Path d(dir);
      dir = d.makeDirectory().makeAbsolute().toString();
      File f(dir);
      if (!f.exists()) f.createDirectories();

      _directory = dir;
  }

Affected versions:

Introduced in 1.9.0 (commit 73ec4e8). Still present in 1.14.2.

Please add relevant environment information:

  • Linux
  • POCO Versions 1.9.0 to 1.14.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions