Skip to content

Commit

Permalink
fix asyncio.exceptions.LimitOverrunError, closes gjcarneiro#56
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcarneiro committed Nov 10, 2021
1 parent 199b52f commit b0d3719
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
36 changes: 36 additions & 0 deletions tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,42 @@ async def producer(fake_stream):
assert (out, job.failed) == (output, expected_failure)


def test_stream_reader_long_line():
loop = asyncio.get_event_loop()
fake_stream = asyncio.StreamReader()
reader = yacron.job.StreamReader(
"cronjob-1", "stderr", fake_stream, 500
)

config, _, _ = yacron.config.parse_config_string(
"""
jobs:
- name: test
command: foo
schedule: "* * * * *"
captureStderr: true
""",
"",
)
job_config = config[0]
job = yacron.job.RunningJob(job_config, None)

async def producer(fake_stream):
fake_stream.feed_data(b"one line\n")
fake_stream.feed_data(b"long line:" + b"1234567890" * 10_000)
fake_stream.feed_data(b"\n")
fake_stream.feed_data(b"another line\n")
fake_stream.feed_eof()

job._stderr_reader = reader
job.retcode = 0
loop.run_until_complete(
asyncio.gather(producer(fake_stream), job._read_job_streams())
)
out = job.stderr
assert out == "one line\nanother line\n"


A_JOB = """
jobs:
- name: test
Expand Down
10 changes: 8 additions & 2 deletions yacron/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ async def _read(self, stream):
limit_top = self.save_limit // 2
limit_bottom = self.save_limit - limit_top
while True:
line = (await stream.readline()).decode("utf-8")
try:
line = (await stream.readline()).decode("utf-8")
except ValueError:
logger.warning(
"job %s: ignored a very long line", self.job_name
)
continue
if not line:
return
out_line = prefix + line
Expand Down Expand Up @@ -189,7 +195,7 @@ async def report(
message["Date"] = datetime.now(timezone.utc)
if mail["html"]:
message.set_payload(body)
message.add_header('Content-Type','text/html')
message.add_header("Content-Type", "text/html")
else:
message.set_content(body)
smtp = aiosmtplib.SMTP(
Expand Down

0 comments on commit b0d3719

Please sign in to comment.