Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fire warnings on too long sync paths #4582

Merged
merged 6 commits into from
Jun 9, 2023
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions core/src/mutagen.ts
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ import split2 from "split2"
import { TypedEventEmitter } from "./util/events"
import pMemoize from "./lib/p-memoize"
import { deline } from "./util/string"
import { emitNonRepeatableWarning } from "./warnings"

const maxRestarts = 10
const mutagenLogSection = "<mutagen>"
@@ -60,9 +61,15 @@ const restartInstructions = (description: string) => deline`

export const mutagenStatusDescriptions = {
"disconnected": "Sync disconnected",
"halted-on-root-emptied": `Sync halted because either the source or target directory was emptied. ${restartInstructions("made sure they're not empty")}`,
"halted-on-root-deletion": `Sync halted because either the source or target was deleted. ${restartInstructions("made sure they exist")}`,
"halted-on-root-type-change": `Sync halted because either the source or target changed type (e.g. from a directory to a file or vice versa). ${restartInstructions("made sure their type is what it should be")}`,
"halted-on-root-emptied": `Sync halted because either the source or target directory was emptied. ${restartInstructions(
"made sure they're not empty"
)}`,
"halted-on-root-deletion": `Sync halted because either the source or target was deleted. ${restartInstructions(
"made sure they exist"
)}`,
"halted-on-root-type-change": `Sync halted because either the source or target changed type (e.g. from a directory to a file or vice versa). ${restartInstructions(
"made sure their type is what it should be"
)}`,
"connecting-alpha": "Sync connected to source",
"connecting-beta": "Sync connected to target",
"watching": "Watching for changes",
@@ -89,7 +96,7 @@ type MutagenStatus = keyof typeof mutagenStatusDescriptions
export const haltedStatuses: MutagenStatus[] = [
"halted-on-root-emptied",
"halted-on-root-deletion",
"halted-on-root-type-change"
"halted-on-root-type-change",
]

export interface SyncConfig {
@@ -622,7 +629,7 @@ export class Mutagen {
cwd: this.dataDir,
args,
log: this.log,
env: getMutagenEnv(this.dataDir),
env: getMutagenEnv({ dataDir: this.dataDir, log: this.log }),
})
} catch (err) {
const unableToConnect = err.message.match(/unable to connect to daemon/)
@@ -632,6 +639,10 @@ export class Mutagen {
await this.ensureDaemon()
await sleep(2000 + loops * 500)
} else {
emitNonRepeatableWarning(
this.log,
`Consider making your Garden project path shorter. Syncing could fail because of Unix socket path length limitations. It's recommended that the Garden project path does not exceed ${MUTAGEN_DATA_DIRECTORY_LENGTH_LIMIT} characters. The actual value depends on the platform and the mutagen version.`
)
throw err
}
}
@@ -758,7 +769,22 @@ export interface SyncSession {
excludedConflicts?: number
}

export function getMutagenEnv(dataDir: string) {
/**
* Exceeding this limit may cause mutagen daemon failures because of the Unix socket path length limitations.
* See
* https://github.com/garden-io/garden/issues/4527#issuecomment-1584286590
* https://github.com/mutagen-io/mutagen/issues/433#issuecomment-1440352501
* https://unix.stackexchange.com/questions/367008/why-is-socket-path-length-limited-to-a-hundred-chars/367012#367012
*/
const MUTAGEN_DATA_DIRECTORY_LENGTH_LIMIT = 70

export function getMutagenEnv({ dataDir, log }: { dataDir: string; log: Log }) {
if (dataDir.length > MUTAGEN_DATA_DIRECTORY_LENGTH_LIMIT) {
emitNonRepeatableWarning(
log,
`Your Garden project path looks too long, that might cause errors while starting the syncs. Consider using a shorter path (no longer than 70 characters).`
vvagaytsev marked this conversation as resolved.
Show resolved Hide resolved
)
}
return {
MUTAGEN_DATA_DIRECTORY: dataDir,
}
@@ -791,7 +817,8 @@ export const mutagenCliSpec: PluginToolSpec = {
{
platform: "darwin",
architecture: "amd64",
url: "https://github.com/garden-io/mutagen/releases/download/v0.15.0-garden-1/mutagen_darwin_amd64_v0.15.0.tar.gz",
url:
"https://github.com/garden-io/mutagen/releases/download/v0.15.0-garden-1/mutagen_darwin_amd64_v0.15.0.tar.gz",
sha256: "370bf71e28f94002453921fda83282280162df7192bd07042bf622bf54507e3f",
extract: {
format: "tar",
@@ -801,7 +828,8 @@ export const mutagenCliSpec: PluginToolSpec = {
{
platform: "darwin",
architecture: "arm64",
url: "https://github.com/garden-io/mutagen/releases/download/v0.15.0-garden-1/mutagen_darwin_arm64_v0.15.0.tar.gz",
url:
"https://github.com/garden-io/mutagen/releases/download/v0.15.0-garden-1/mutagen_darwin_arm64_v0.15.0.tar.gz",
sha256: "a0a7be8bb37266ea184cb580004e1741a17c8165b2032ce4b191f23fead821a0",
extract: {
format: "tar",
16 changes: 13 additions & 3 deletions core/src/plugins/kubernetes/commands/sync.ts
Original file line number Diff line number Diff line change
@@ -84,7 +84,12 @@ export const syncPause: PluginCommand = {
log.info(`Pausing ${activeSyncSessionNames.length} syncs.`)
for (const sessionName of activeSyncSessionNames) {
log.debug(`Pausing sync session ${sessionName}`)
await mutagen.exec({ cwd: dataDir, log, env: getMutagenEnv(dataDir), args: ["sync", "pause", sessionName] })
await mutagen.exec({
cwd: dataDir,
log,
env: getMutagenEnv({ dataDir, log }),
args: ["sync", "pause", sessionName],
})
}
}

@@ -125,7 +130,12 @@ export const syncResume: PluginCommand = {
log.info(`Resuming ${pausedSyncSessionNames.length} syncs.`)
for (const sessionName of pausedSyncSessionNames) {
log.debug(`Resuming sync session ${sessionName}`)
await mutagen.exec({ cwd: dataDir, log, env: getMutagenEnv(dataDir), args: ["sync", "resume", sessionName] })
await mutagen.exec({
cwd: dataDir,
log,
env: getMutagenEnv({ dataDir, log }),
args: ["sync", "resume", sessionName],
})
}
}

@@ -138,7 +148,7 @@ async function getMutagenSyncSessions({ mutagen, dataDir, log }: { mutagen: Plug
const res = await mutagen.exec({
cwd: dataDir,
log,
env: getMutagenEnv(dataDir),
env: getMutagenEnv({ dataDir, log }),
args: ["sync", "list", "--template={{ json . }}"],
})
return parseSyncListResult(res)
2 changes: 1 addition & 1 deletion core/src/plugins/kubernetes/container/build/common.ts
Original file line number Diff line number Diff line change
@@ -127,7 +127,7 @@ export async function syncToBuildSync(params: SyncToSharedBuildSyncParams) {
log,
key,
logSection: action.key(),
sourceDescription: `Module ${action.name} build path`,
sourceDescription: `${action.kind} ${action.name} build path`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch 👍

targetDescription: "Build sync Pod",
config: {
alpha: sourcePath,