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

Fix a bug with trigger payload validation in linux.FileWatchSensor sensor #4491

Merged
merged 10 commits into from Jan 8, 2019

Conversation

Projects
None yet
2 participants
@Kami
Copy link
Member

Kami commented Jan 7, 2019

This pull request fixes an issue with file watch sensor not working correctly since the trigger payload validation has been enabled by default a couple of releases ago.

The root cause was that validate_trigger_payload() method only worked with TriggerType reference, but not with Trigger reference.

FileWatch sensor is a bit special since it's the only sensor which works with actual triggers and not trigger types (aka issue didn't affect other sensors).

Resolves #4486

TODO

  • Test case

Kami added some commits Jan 3, 2019

Fix two issues in FileWatchSensor:
1. Mitigate / avoid race when calling add_file() before tailer has been
initialized
2. Fix a bug with failing to dispatch a trigger due to code using
invalid trigger type reference (it uses trigger ref instead of trigger
type ref)
Fix validate_trigger_payload() method so it also works if a trigger
reference and not trigger type reference is passed to it.

@Kami Kami added the bug label Jan 7, 2019

@Kami Kami added this to the 2.10.2 milestone Jan 7, 2019

@@ -42,6 +44,9 @@ def add_trigger(self, trigger):
if not self._trigger:
raise Exception('Trigger %s did not contain a ref.' % trigger)

# Wait a bit to avoid initialization race in logshipper library
eventlet.sleep(1.0)

This comment has been minimized.

@Kami

Kami Jan 7, 2019

Member

There is an edge case in logshipper library.

If a trigger is added and add_file is called before the tailer is initialized, an exception will be thrown and the sensor will die / crash (this can happen because add_trigger method is called asynchronously and it could be called before run() and tailer fully initialized).

This comment has been minimized.

@bigmstone

bigmstone Jan 7, 2019

Contributor

:(

This comment has been minimized.

@Kami

Kami Jan 8, 2019

Member

Yeah, it's not ideal.

I could make it 100% deterministic by shuffling around the code (set initialized or similar variable to True inside run() and only proceed inside add_handler when that variable is True).

I think that's too complicated though since sleep seems to work just as fine (and it's one line of code).

It also only affects a single sensor right now so there is no point in handling that inside sensor container / base sensor class code.

@Kami Kami requested a review from bigmstone Jan 7, 2019

@@ -42,6 +44,9 @@ def add_trigger(self, trigger):
if not self._trigger:
raise Exception('Trigger %s did not contain a ref.' % trigger)

# Wait a bit to avoid initialization race in logshipper library
eventlet.sleep(1.0)

This comment has been minimized.

@bigmstone

bigmstone Jan 7, 2019

Contributor

:(

@Kami Kami merged commit 61b1de4 into master Jan 8, 2019

5 checks passed

ci/circleci: packages Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
st2/e2e/centos7 E2E tests have finished successfully
Details
st2/e2e/ubuntu16 E2E tests have finished successfully
Details
st2/e2e/ubuntu18 E2E tests have finished successfully
Details

@Kami Kami deleted the file_watch_payload_validation_fix branch Jan 8, 2019

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