Skip to content

Conversation

@kayaj1009
Copy link

@kayaj1009 kayaj1009 commented Jan 6, 2026

Description

This PR fixes SFTP connection poisoning and concurrent race conditions when using the SFTP binding with enterprise SFTP servers like Axway MFT.

Changes

  • Close file handles properly inside mutex-protected closures - File handles are now opened, used, and closed within the same atomic operation
  • Use Lock() instead of RLock() for full operation serialization - Prevents concurrent operations that confuse strict SFTP servers
  • Make create/write atomic within mutex protection - The entire create+write operation now happens as a single protected unit
  • Improve shouldReconnect() error classification - Properly detects StatusError types via errors.As() to avoid unnecessary reconnection attempts
  • Add string matching for wrapped errors - Catches errors like "permission denied", "not a directory", "file exists" that shouldn't trigger reconnection
  • Add unit tests for error classification - Comprehensive test coverage for shouldReconnect() logic

Issue reference

Fixes #4078

Checklist

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation
  • Created the dapr/docs PR

Fixes dapr#4078

- Close file handles properly inside mutex-protected closures
- Use Lock() instead of RLock() for full operation serialization
- Make create/write atomic within mutex protection
- Improve shouldReconnect() error classification for SFTP StatusError
- Add string matching for wrapped errors (permission denied, not a directory, etc.)
- Add unit tests for error classification

Signed-off-by: kayaj1009 <[email protected]>
Comment on lines 204 to 208
func (c *Client) do(fn func() error) error {
c.lock.RLock()
defer c.lock.RUnlock()
c.lock.Lock()
defer c.lock.Unlock()
return fn()
}
Copy link
Contributor

@javier-aliaga javier-aliaga Jan 7, 2026

Choose a reason for hiding this comment

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

@kayaj1009 I think we should go with a configurable approach as not all sftp server needs this strict sync. Probably better if you add a component config to set strict to true in case you need it. Then we should have do and doStrict funcs and use them based on config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SFTP binding broken with Axway MFT - connection poisoning on first error

2 participants