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

Gracefully exit on SIGPIPE #128

Merged
merged 1 commit into from Jun 3, 2017
Merged

Conversation

rwolfson
Copy link
Contributor

Piping to utilities that close out their pipe by design (such as head) causes a traceback message when the pipe is closed. This tweak catches that particular error condition and exits, and lets other IO failures continue to escalate.

Before:

(venv) $ ./command_line.py get log_group_sanitized ALL | head
log_group_sanitized log_stream_sanitized1 Test log message from 127509dae97b (Wed Apr 12 23:24:55 UTC 2017)
log_group_sanitized log_stream_sanitized2 Test log message from 4edd0756f357 (Wed Apr 12 23:24:56 UTC 2017)
log_group_sanitized log_stream_sanitized1 Test log message from 127509dae97b (Wed Apr 12 23:24:58 UTC 2017)
log_group_sanitized log_stream_sanitized2 Test log message from 4edd0756f357 (Wed Apr 12 23:25:00 UTC 2017)
log_group_sanitized log_stream_sanitized1 Test log message from 127509dae97b (Wed Apr 12 23:25:01 UTC 2017)
log_group_sanitized log_stream_sanitized1 Test log message from 127509dae97b (Wed Apr 12 23:25:04 UTC 2017)
log_group_sanitized log_stream_sanitized1 Test log message from 127509dae97b (Wed Apr 12 23:25:05 UTC 2017)
log_group_sanitized log_stream_sanitized2 Test log message from 4edd0756f357 (Wed Apr 12 23:25:05 UTC 2017)
log_group_sanitized log_stream_sanitized2 Test log message from 4edd0756f357 (Wed Apr 12 23:25:08 UTC 2017)
log_group_sanitized log_stream_sanitized1 Test log message from 127509dae97b (Wed Apr 12 23:25:10 UTC 2017)

================================================================================
You've found a bug! Please, raise an issue attaching the following traceback
https://github.com/jorgebastida/awslogs/issues/new
--------------------------------------------------------------------------------
Version: 0.9.0
Python: 2.7.5 (default, Sep 15 2016, 22:37:39)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
boto3 version: 1.4.4
Platform: Linux-3.10.0-327.10.1.el7.x86_64-x86_64-with-centos-7.2.1511-Core
Config: {'output_timestamp_enabled': False, 'output_group_enabled': True, 'end': None, 'aws_secret_access_key': 'SENSITIVE', 'log_stream_name': 'ALL', 'watch': False, 'aws_region': None, 'aws_session_token': 'SENSITIVE', 'start': '5m', 'aws_profile': 'SENSITIVE', 'filter_pattern': None, 'log_group_name': 'log_group_sanitized', 'output_ingestion_time_enabled': False, 'query': None, 'func': 'list_logs', 'aws_access_key_id': 'SENSITIVE', 'color_enabled': True, 'output_stream_enabled': True}
Args: ['./command_line.py', 'get', 'log_group_sanitized', 'ALL']

Traceback (most recent call last):
  File "/homedir_sanitized/src/awslogs/awslogs/bin.py", line 172, in main
    getattr(logs, options.func)()
  File "/homedir_sanitized/src/awslogs/awslogs/core.py", line 187, in list_logs
    consumer()
  File "/homedir_sanitized/src/awslogs/awslogs/core.py", line 185, in consumer
    sys.stdout.flush()
IOError: [Errno 32] Broken pipe
================================================================================

After:

(venv) $ ./command_line.py get log_group_sanitized ALL | head
log_group_sanitized log_stream_sanitized1 Test log message from 127509dae97b (Wed Apr 12 23:25:33 UTC 2017)
log_group_sanitized log_stream_sanitized2 Test log message from 4edd0756f357 (Wed Apr 12 23:25:33 UTC 2017)
log_group_sanitized log_stream_sanitized1 Test log message from 127509dae97b (Wed Apr 12 23:25:35 UTC 2017)
log_group_sanitized log_stream_sanitized2 Test log message from 4edd0756f357 (Wed Apr 12 23:25:35 UTC 2017)
log_group_sanitized log_stream_sanitized1 Test log message from 127509dae97b (Wed Apr 12 23:25:36 UTC 2017)
log_group_sanitized log_stream_sanitized1 Test log message from 127509dae97b (Wed Apr 12 23:25:40 UTC 2017)
log_group_sanitized log_stream_sanitized2 Test log message from 4edd0756f357 (Wed Apr 12 23:25:40 UTC 2017)
log_group_sanitized log_stream_sanitized1 Test log message from 127509dae97b (Wed Apr 12 23:25:41 UTC 2017)
log_group_sanitized log_stream_sanitized1 Test log message from 127509dae97b (Wed Apr 12 23:25:45 UTC 2017)
log_group_sanitized log_stream_sanitized2 Test log message from 4edd0756f357 (Wed Apr 12 23:25:45 UTC 2017)
(venv) $

@coveralls
Copy link

coveralls commented Apr 12, 2017

Coverage Status

Coverage decreased (-1.3%) to 91.398% when pulling 52067df on rwolfson:sigpipe into df9366e on jorgebastida:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.3%) to 91.398% when pulling 52067df on rwolfson:sigpipe into df9366e on jorgebastida:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.3%) to 91.398% when pulling 52067df on rwolfson:sigpipe into df9366e on jorgebastida:master.

@rwolfson
Copy link
Contributor Author

Cross-linking with #122 #93 #101

@rwolfson
Copy link
Contributor Author

Regarding the failed flake8 test - it looks like the prior complexity was 25 and tox.ini has max-complexity set a hair above at 26. After this change, the function is up to 28. Thoughts on raising that threshold, or is a refactor in order?

@jorgebastida jorgebastida merged commit 52067df into jorgebastida:master Jun 3, 2017
@jorgebastida
Copy link
Owner

Thank you very much for your contribution @rwolfson

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

3 participants