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

SftpSubsystem eats exceptions #313

Closed
Thrameos opened this issue Jan 19, 2023 · 2 comments · Fixed by #314
Closed

SftpSubsystem eats exceptions #313

Thrameos opened this issue Jan 19, 2023 · 2 comments · Fixed by #314

Comments

@Thrameos
Copy link
Contributor

Version

2.9.3

Bug description

While trying to implement a virtual file system for SFTPD, I ran into a condition in which the connection would close but there was nothing in the logs. After 5 hours of trying to configure the logger all I could see is DEBUG messages, but no log of the exception or error. I eventually traced it down that although there is a master catch in SftpSubsystem.run, it was never being reached. It appears that AbstractSftpSubsystemHelper contains a lot of code with this sort of pattern...

      } catch (IOException | RuntimeException e) {
            sendStatus(prepareReply(buffer), id, e, SftpConstants.SSH_FXP_OPEN, path);
            return;
        }

It seems like poor practice to not log something when an exception occurs.

To reproduce this I implemented a custom FileSystemFactory which returned MyFileSystem in which getSeparator() throw an exception. To hit multiple points I had to proxy Path, FileSystem, and FileSystemProvider to the normal versions. The exception must happen in the Path, FileSystem, or FileSystemProvider. Throws in FileSystemFactory are caught properly as SftpSubsystem catches during prepare, but not in doProcess.

Actual behavior

Nothing was logged.

Expected behavior

A log message with the source of the exception. If this is addressed, perhaps this should be logged at the DEBUG level as this was not normally logged in the past. After all there are a lot of tolerable exceptions (missing file, permissions, etc) that are not errors for normal operation.

Relevant log output

No response

Other information

Logging was configured with log4j with DEBUG to console. But the lack of output is programmatic rather than the logger, so it should be universal.

@tomaswolf
Copy link
Member

There is debug logging in sendStatus(), but it's true that it doesn't log the exception itself or its stack trace.

Additional logging in the first variant (with the Throwable parameter) might be good indeed.

Do you want to provide a PR?

@Thrameos
Copy link
Contributor Author

I gave it a shot. I am not sure what information is needed to identify the source. I put the session and the id assuming that it matches the other calls.

tomaswolf pushed a commit to Thrameos/mina-sshd that referenced this issue Jan 25, 2023
Log exceptions in the SftpSubsystem before sending back a failure
status reply. This helps figuring out from the server logs why a
particular SFTP request elicited a failure status reply.

Bug: apache#313
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 a pull request may close this issue.

2 participants