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

[AIRFLOW-3528] handle socket exception with SFTPOperator #4325

Closed
wants to merge 1 commit into from
Closed

[AIRFLOW-3528] handle socket exception with SFTPOperator #4325

wants to merge 1 commit into from

Conversation

eladkal
Copy link
Contributor

@eladkal eladkal commented Dec 16, 2018

Jira

Description

add try/exception to catch socket exceptions

add try/exception to catch socket exceptions
@codecov-io
Copy link

Codecov Report

Merging #4325 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #4325   +/-   ##
======================================
  Coverage    78.1%   78.1%           
======================================
  Files         201     201           
  Lines       16471   16471           
======================================
  Hits        12864   12864           
  Misses       3607    3607

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1023e8c...c83a4e5. Read the comment docs.

@@ -122,7 +122,11 @@ def execute(self, context):
self.ssh_hook.remote_host = self.remote_host

with self.ssh_hook.get_conn() as ssh_client:
sftp_client = ssh_client.open_sftp()
try:
Copy link
Member

Choose a reason for hiding this comment

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

Does it need to be a Custom (Airflow) Exception?
Why can't the original exception just be raised?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently it raises AirflowException as it's being handled at this line:
https://github.com/apache/incubator-airflow/blob/c83a4e5b952baa8d390e94d27fd12df888d3113e/airflow/contrib/operators/sftp_operator.py#L158

The propose here is just not to show the "Error while transferring (file_msg)" as this is confusing and file_msg is None.

@ashb
Copy link
Member

ashb commented Dec 18, 2018

This fix I don't think will do what we want, as I think now this will end up ultimately logging this as a message:

Error while transferring None, error: Error while connecting client, error: socket timed out

(I took a guess at what might be in the OSError).

Which means we probably need to add some tests, via mocking, that makes open_sftp fail with an exception. And then once we have tests we can be sure the error is reported right in this case.

@eladkal
Copy link
Contributor Author

eladkal commented Dec 18, 2018

This fix I don't think will do what we want, as I think now this will end up ultimately logging this as a message:

Error while transferring None, error: Error while connecting client, error: socket timed out

(I took a guess at what might be in the OSError).

Which means we probably need to add some tests, via mocking, that makes open_sftp fail with an exception. And then once we have tests we can be sure the error is reported right in this case.

I'm not sure what you mean... Since Python 3.3 socket.error is deprecated. It raised OSError instead.
https://docs.python.org/3/library/socket.html#socket.error

This PR doesn't attempt to solve the problem regarding why the connection fails. It only fix the message in order to avoid confusion. This problem was reported on Slack. @XD-DENG said that he will try to investigate about why the connection fails.

@ashb
Copy link
Member

ashb commented Dec 18, 2018

I guessed at what error it might report. The main thing is you have try-inside-try, so this won't do what you expect.

Additionally the error that was reporting was 'NoneType' object has no attribute 'open_sftp' which means no exception is being thrown, instead self.ssh_hook.get_conn() as ssh_client is returning None.

So the except you added (capturing OSError) won't ever get triggered.

Tests :)

@XD-DENG
Copy link
Member

XD-DENG commented Dec 18, 2018

Agree with @ashb on the exception type to catch. Based on the exception/log shared in the Slack thread, it's an AttributeError instead of OSError. This PR can not (completely) handle the issue shared in the Slack thread.

@eladkal
Copy link
Contributor Author

eladkal commented Dec 18, 2018

OK. Got it.
In this case I'll leave this to @XD-DENG or whoever wants to pick this up. From what was reported regardless of the error handling the operator doesn't seem to work. This exceed from the scope of what I can help with at this point.

@eladkal eladkal closed this Dec 18, 2018
@ashb
Copy link
Member

ashb commented Dec 18, 2018

Okay, thanks for trying though!

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.

None yet

5 participants