{"record":{"id":"d85d6d08673e9066","repo":"slimtoolkit/slim","slug":"cannot-create-execution-open-event-file-q-faile","errorCode":null,"errorMessage":"cannot create execution - open event file %q failed: %w","messagePattern":"cannot create execution - open event file %q failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/sensor/execution/standalone.go","lineNumber":44,"sourceCode":"}\n\nfunc NewStandalone(\n\tctx context.Context,\n\tcommandFileName string,\n\teventFileName string,\n\tlifecycleHookCommand string,\n) (Interface, error) {\n\t// fsutil.Touch() creates (potentially missing) folder(s).\n\tif err := fsutil.Touch(eventFileName); err != nil {\n\t\treturn nil, fmt.Errorf(\n\t\t\t\"cannot create execution - touch event file %q failed: %w\",\n\t\t\teventFileName, err,\n\t\t)\n\t}\n\n\teventFile, err := os.OpenFile(eventFileName, os.O_APPEND|os.O_WRONLY|os.O_SYNC, 0644)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\n\t\t\t\"cannot create execution - open event file %q failed: %w\",\n\t\t\teventFileName, err,\n\t\t)\n\t}\n\n\tcmd, err := readCommandFile(commandFileName)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\n\t\t\t\"cannot create execution - cannot read command file %q: %w\",\n\t\t\tcommandFileName, err,\n\t\t)\n\t}\n\n\tcommandCh := make(chan command.Message, 10)\n\tcommandCh <- &cmd\n\n\tgo control.HandleControlCommandQueue(ctx, commandFileName, commandCh)\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/sensor/execution/standalone.go#L26-L62","documentation":"After successfully touching the event file, NewStandalone opens it with os.OpenFile using O_APPEND|O_WRONLY|O_SYNC to append events. If the OS refuses to open the file for writing, the execution cannot be created and this error wraps the OS error.","triggerScenarios":"Calling NewStandalone when eventFileName exists but cannot be opened for append/write: file owned by another user, no write permission, path is a directory, or too many open files (EMFILE).","commonSituations":"Event file pre-created by an init container with root ownership while sensor runs as non-root; eventFileName actually a directory; fd limit exhausted in long-running containers.","solutions":["Read the wrapped OS error and fix permissions/ownership on the event file (chmod 0644 / chown to sensor user).","Ensure eventFileName is a regular file, not a directory or symlink to an unwritable target.","Check ulimit -n / fs.file-max if the cause is 'too many open files'."],"exampleFix":"// before\niface, err := execution.NewStandalone(cmdFile, \"/var/run/sensor\", hook) // path is a directory\n// after\niface, err := execution.NewStandalone(cmdFile, \"/var/run/sensor/events\", hook) // regular file path","handlingStrategy":"validation","validationCode":"func canOpenForAppend(path string) error {\n    fi, err := os.Stat(path)\n    if err == nil && fi.IsDir() {\n        return fmt.Errorf(\"%s is a directory\", path)\n    }\n    f, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644)\n    if err != nil { return err }\n    return f.Close()\n}","typeGuard":"func isOpenFailure(err error) bool {\n    var pe *fs.PathError\n    return errors.As(err, &pe) && errors.Is(pe.Err, os.ErrPermission)\n}","tryCatchPattern":"exec, err := execution.NewStandalone(cmdFile, eventFile, hook)\nif err != nil && strings.Contains(err.Error(), \"open event file\") {\n    log.Fatalf(\"cannot open event file for append: %v\", err)\n}","preventionTips":["Do not point eventFileName at a directory; use a dedicated file path.","Align file ownership between init containers and the sensor user.","Monitor open fd counts in long-running pods and raise ulimit -n.","Let the sensor create the file itself rather than pre-creating with restrictive modes."],"tags":["filesystem","file-open","permissions","standalone-execution"],"backgroundTag":"file-permission-denied","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}