Skip to content

Conversation

@ffranr
Copy link
Contributor

@ffranr ffranr commented Nov 25, 2025

This PR addresses #1869, where a user hit SQLITE_IOERR_GETTEMPPATH (6410) during tapd operation. The goal is to fail fast at startup if SQLite cannot access a writable temporary directory, instead of surfacing a late, opaque I/O error.

Summary of changes

  • Validate SQLite temp directory at startup

    • On tapd initialization, determine candidate temp directories using:
      • SQLITE_TMPDIR and TMPDIR
      • Platform default temp locations as a fallback
    • Perform a writability check on the selected directory so that we can abort early with a clear configuration error if it is not writable.
    • The intent is to catch container or host setups where /tmp or similar paths are not writable, which would later cause SQLITE_IOERR_GETTEMPPATH.
  • Add config flag to skip the check

    • Introduce a new tapcfg option to skip the SQLite temp directory writability check at startup.

    • This gives operators an escape hatch in environments where:

      • The temp directory is managed in a non standard way, or
      • They explicitly prefer to rely on SQLite’s own behavior instead of the upfront check.

Rationale

  • SQLITE_IOERR_GETTEMPPATH (6410) typically indicates that SQLite’s VFS cannot determine or use a suitable directory for temporary files.
  • In production and containerized environments this often points to a misconfigured or read only temp volume.
  • Detecting this at startup with an explicit error and remediation hint is preferable to failing later during normal operation.

@gemini-code-assist
Copy link

Summary of Changes

Hello @ffranr, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of tapd by proactively validating SQLite's temporary directory access at startup. It introduces a mechanism to check for writable temporary directories, preventing runtime SQLITE_IOERR_GETTEMPPATH errors, and includes an opt-out configuration flag for advanced users or specific deployment scenarios.

Highlights

  • SQLite Temporary Directory Validation: Implemented a check during tapd initialization to determine and verify the writability of candidate temporary directories (e.g., SQLITE_TMPDIR, TMPDIR, /var/tmp, /usr/tmp, /tmp). This ensures that tapd fails early with a clear error if SQLite cannot access a writable temporary directory, preventing SQLITE_IOERR_GETTEMPPATH errors during operation.
  • Opt-out Configuration Flag: Introduced a new sqlite.skiptmpdircheck configuration option, allowing operators to bypass the temporary directory writability check. This provides flexibility for environments with non-standard temporary directory management or when preferring SQLite's default behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a valuable startup check to validate the writability of SQLite's temporary directory, preventing opaque runtime errors. The implementation is sound and includes a useful opt-out flag. My review focuses on removing a piece of leftover code, improving an error message for better diagnostics, and refactoring a function to enhance readability and maintainability.

Comment on lines 47 to 82
// SQLite will use the first available temp directory; we mirror that
// behavior by trying environment variables and standard fallback
// directories in order.
var errs []string
if dir := os.Getenv("SQLITE_TMPDIR"); dir != "" {
if err := ensureDirWritable(dir); err != nil {
err = fmt.Errorf("(env=SQLITE_TMPDIR) %w", err)
errs = append(errs, err.Error())
} else {
return nil
}
}

if dir := os.Getenv("TMPDIR"); dir != "" {
if err := ensureDirWritable(dir); err != nil {
err = fmt.Errorf("(env=TMPDIR) %w", err)
errs = append(errs, err.Error())
} else {
return nil
}
}

for _, dir := range []string{"/var/tmp", "/usr/tmp", "/tmp"} {
if err := ensureDirWritable(dir); err != nil {
errs = append(errs, err.Error())
continue
}

return nil
}

return fmt.Errorf("no writable temp directory found; attempts=%s",
strings.Join(errs, "; "))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for checking different temporary directories is a bit repetitive. You can refactor this to be more DRY by using a slice of structs to hold the directories and their sources, and then iterating over them. This also makes it easier to add more directories to check in the future and ensures consistent error reporting.

	// SQLite will use the first available temp directory; we mirror that
	// behavior by trying environment variables and standard fallback
	// directories in order.
	var errs []string

	type dirSource struct {
		path   string
		source string
	}

	sources := []dirSource{
		{path: os.Getenv("SQLITE_TMPDIR"), source: "env=SQLITE_TMPDIR"},
		{path: os.Getenv("TMPDIR"), source: "env=TMPDIR"},
		{path: "/var/tmp", source: "fallback=/var/tmp"},
		{path: "/usr/tmp", source: "fallback=/usr/tmp"},
		{path: "/tmp", source: "fallback=/tmp"},
	}

	for _, s := range sources {
		if s.path == "" {
			continue
		}

		if err := ensureDirWritable(s.path); err != nil {
			errs = append(errs, fmt.Errorf("(%s) %w", s.source, err).Error())
		} else {
			return nil
		}
	}

	return fmt.Errorf("no writable temp directory found; attempts=%s",
		strings.Join(errs, "; "))

@coveralls
Copy link

coveralls commented Nov 25, 2025

Pull Request Test Coverage Report for Build 19701408303

Details

  • 42 of 60 (70.0%) changed or added relevant lines in 3 files are covered.
  • 46 unchanged lines in 13 files lost coverage.
  • Overall coverage increased (+0.03%) to 56.655%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tapcfg/server.go 8 11 72.73%
tapcfg/validate.go 33 48 68.75%
Files with Coverage Reduction New Missed Lines %
mssmt/compacted_tree.go 2 78.57%
tapdb/assets_common.go 2 78.34%
tapdb/mssmt.go 2 90.45%
universe_rpc_diff.go 2 76.0%
universe/syncer.go 2 84.22%
tapchannel/aux_leaf_signer.go 3 43.53%
tapgarden/planter.go 3 80.3%
universe/archive.go 3 81.74%
authmailbox/receive_subscription.go 4 73.31%
tapgarden/caretaker.go 4 76.63%
Totals Coverage Status
Change from base Build 19660052975: 0.03%
Covered Lines: 64648
Relevant Lines: 114109

💛 - Coveralls

Copy link
Member

@jtobin jtobin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one. There's that one conditional block artifact that should be removed, but otherwise LGTM. 👍

Adds logic to validate writable temp directories for SQLite operations
during initialization. Handles environment variables like
`SQLITE_TMPDIR` and `TMPDIR`, and falls back to standard temp
directories.
Add a configuration flag to disable the SQLite temporary directory
writability check performed at startup.
@ffranr ffranr force-pushed the wip/check-tmp-env-writable branch from 786fd89 to f16b0cd Compare November 26, 2025 11:00
Copy link
Member

@GeorgeTsagk GeorgeTsagk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jtobin jtobin added this pull request to the merge queue Nov 26, 2025
Merged via the queue into main with commit 7013ac3 Nov 26, 2025
19 checks passed
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Taproot-Assets Project Board Nov 26, 2025
@ffranr ffranr deleted the wip/check-tmp-env-writable branch November 26, 2025 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

[bug]: unable to marshal asset: unable to fetch all asset meta: unknown sqlite error: disk I/O error (6410)

5 participants