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

[JENKINS-70922] Remove Prototype Ajax.Request usage from select.js #7982

Merged
merged 1 commit into from
May 18, 2023

Conversation

timja
Copy link
Member

@timja timja commented May 11, 2023

See JENKINS-70922.

Testing done

Manually tested by clicking through the UI where it's used adding console.log to see what was using it.
Credentials were fine.
Ran mvn test -Dtest=hudson.RelativePathTest which provides test coverage (and it caught an issue with parameters originally)

Draft till ran through ATH

Proposed changelog entries

  • Entry 1: Issue, human-readable text
  • […]

Proposed upgrade guidelines

N/A

Submitter checklist

  • The Jira issue, if it exists, is well-described.
  • The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood (see examples).
    • Fill in the Proposed upgrade guidelines section only if there are breaking changes or changes that may require extra steps from users during upgrade.
  • There is automated testing or an explanation as to why this change has no tests.
  • New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadocs, as appropriate.
  • New deprecations are annotated with @Deprecated(since = "TODO") or @Deprecated(forRemoval = true, since = "TODO"), if applicable.
  • New or substantially changed JavaScript is not defined inline and does not call eval to ease future introduction of Content Security Policy (CSP) directives (see documentation).
  • For dependency updates, there are links to external changelogs and, if possible, full differentials.
  • For new APIs and extension points, there is a link to at least one consumer.

Desired reviewers

@mention

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There are at least two (2) approvals for the pull request and no outstanding requests for change.
  • Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
  • Changelog entries in the pull request title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood.
  • Proper changelog labels are set so that the changelog can be generated automatically.
  • If the change needs additional upgrade steps from users, the upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the pull request title (see example).
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

This was meant to be a starting point for further exploration, not a final solution. I merely sought to demonstrate that interleaved callbacks from refill operations were interfering with each other and causing a data race.

(1) First, I think we should determine what is firing the second change event. Does it make sense, or is it unnecessary? If we can eliminate that, the entire problem is solved.

(2) If the second change event is necessary, then I think we should explore whether the refill process can be made thread-safe with traditional techniques (e.g., reducing the use of shared data).

Only if the second change event is necessary (1) and it cannot be made thread-safe (2) do I think we should implement mutual exclusion (3) as in my cheesy sleep and retry demonstration.

And if we are to implement mutual exclusion (3), my cheesy sleep and retry demonstration is certainly not a good way to do it. Doing a quick Google search, I found a handful of mutex libraries. Or for a library-less option, anyone can implement a Lamport lock at home (which is essentially a mathematically correct version of my cheesy sleep and retry demonstration).

@timja
Copy link
Member Author

timja commented May 15, 2023

(1) First, I think we should determine what is firing the second change event. Does it make sense, or is it unnecessary? If we can eliminate that, the entire problem is solved.

It's only a single event but there's multiple event handlers registered to the element

image

Verified by removing one of the event handlers, and it only runs once.

@timja
Copy link
Member Author

timja commented May 15, 2023

By sticking on a breakpoint and looking at the callstack I tracked the second event listener to this code:
https://github.com/jenkinsci/credentials-plugin/blob/b96f366e7badeedaf69724991e44409be11a07b6/src/main/resources/lib/credentials/select/select.js#L274-L282

Hopefully it can just be safely removed.

@timja
Copy link
Member Author

timja commented May 15, 2023

It can't be removed as-is, the steps from jenkinsci/credentials-plugin#23 still reproduce the issue

@timja timja requested a review from basil May 15, 2023 10:11
@timja timja added the skip-changelog Should not be shown in the changelog label May 15, 2023
@timja
Copy link
Member Author

timja commented May 15, 2023

That works now, thoughts @basil?

(Will need ATH testing as well)

@basil
Copy link
Member

basil commented May 16, 2023

This is still failing ATH.

@timja
Copy link
Member Author

timja commented May 16, 2023

This is still failing ATH.

Hmm it's a really weird one.

When running through ATH it selects the credential and then it gets reset to none super quickly.
If I pause the test and do it myself it's just fine =/

It sometimes works too but fails most of the time, and if you pause before selecting it does work

@timja
Copy link
Member Author

timja commented May 16, 2023

Tests seem to mostly pass after: 9bee3b1

I'm having to use chrome locally as Firefox isn't working on newer versions which might be why some tests are failing.

image

Let's see how it goes on the pipeline

@basil
Copy link
Member

basil commented May 16, 2023

When running through ATH it selects the credential and then it gets reset to none super quickly.
If I pause the test and do it myself it's just fine =/

That would be evidence that the data race still exists.

@timja
Copy link
Member Author

timja commented May 16, 2023

When running through ATH it selects the credential and then it gets reset to none super quickly.
If I pause the test and do it myself it's just fine =/

That would be evidence that the data race still exists.

Yes that was resolved by 9bee3b1

@basil
Copy link
Member

basil commented May 16, 2023

Yes that was resolved by 9bee3b1

Aha, this was the real fix, and the change to refillOnChange-listener-attached in war/src/main/webapp/scripts/hudson-behavior.js does not seem to make any difference when testing. So please revert the changes to hudson-behavior.js. If that change makes sense for independent reasons (e.g., efficiency, correctness, etc), it may be proposed as a separate PR, but it does not seem related to the primary purpose of this PR.

@basil basil self-assigned this May 16, 2023
@timja timja force-pushed the JENKINS-70922-selectjs branch from c450379 to 9432504 Compare May 16, 2023 21:29
Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

ATH is looking good on the latest revision. Nice job taking this across the finish line!

@timja timja marked this pull request as ready for review May 17, 2023 05:49
@timja
Copy link
Member Author

timja commented May 17, 2023

/label ready-for-merge


This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback.

Thanks!

@comment-ops-bot comment-ops-bot bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label May 17, 2023
@basil basil merged commit d3f7958 into jenkinsci:master May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback skip-changelog Should not be shown in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants