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

Race condition and crash on Swagger UI startup #1126

Closed
chornyi opened this issue Jan 6, 2016 · 19 comments
Closed

Race condition and crash on Swagger UI startup #1126

chornyi opened this issue Jan 6, 2016 · 19 comments
Labels
Milestone

Comments

@chornyi
Copy link
Contributor

chornyi commented Jan 6, 2016

When I load Swagger UI by going to http://<host>/swagger-ui.html, about 10% of the time I get an empty screen and this error in JS console:

Uncaught TypeError: Cannot read property 'headerView' of undefined
    (anonymous function)  @ springfox.js:22
    p.event.dispatch @ jquery-1.8.0.min.js:2
    g.handle.h @ jquery-1.8.0.min.js:2
    p.event.trigger @ jquery-1.8.0.min.js:2
    (anonymous function) @ jquery-1.8.0.min.js:2
    p.extend.each @ jquery-1.8.0.min.js:2
    p.fn.p.each @ jquery-1.8.0.min.js:2
    p.fn.extend.trigger @ jquery-1.8.0.min.js:2
    p.fn.(anonymous function) @ jquery-1.8.0.min.js:2
    (anonymous function) @ springfox.js:50
    k @ jquery-1.8.0.min.js:2
    l.fireWith @ jquery-1.8.0.min.js:2
    y @ jquery-1.8.0.min.js:2d @ jquery-1.8.0.min.js:2

This happens both on Chrome and Firefox and I see it happen more often when I access the page over the network as opposed to localhost.

I interpret this as a race condition between the Swagger UI application initialization and the Springfox code to set the base URI when the $('#select_baseUrl').change() event is fired during the $(document).ready() callback. Sometimes these callbacks are fired before window.swaggerUi is set.

I'm talking about these two places in code:
https://github.com/springfox/springfox/blob/master/springfox-swagger-ui/src/web/swagger-ui.html#L30
https://github.com/springfox/springfox/blob/master/springfox-swagger-ui/src/web/js/springfox.js#L35

Is there a reason why this initialization happens in two functions that are executed in parallel?

Version 2.3.1

@dilipkrish
Copy link
Member

The idea behind the two initializations was to preserve swagger-ui.html so that its easy to take in updates from the mother ship. Open to ideas on how best to do that.

@chornyi
Copy link
Contributor Author

chornyi commented Jan 6, 2016

Let me see if I can figure out how to build this gradle thing and make the initialization sequential.

@dilipkrish
Copy link
Member

Let me know if you need help with that.. but it fairly straight forward

./gradlew :springfox-swagger-ui:build

will build your project. All it does is downloads the latest version of swagger-ui from the repo and repackages it as a webjar along with springfox customizations.

Thanks for looking into it! 👍

chornyi added a commit to chornyi/springfox that referenced this issue Jan 6, 2016
@chornyi
Copy link
Contributor Author

chornyi commented Jan 6, 2016

I did consolidate initialization into one file as they are tightly coupled anyways. @dilipkrish, let me know if you think it is a bad idea.

I cannot reproduce the problem after the change.

@tommack
Copy link

tommack commented Jan 8, 2016

I'm also seeing this under the same conditions: upgraded library, tested locally, pushed, then realized it was broken.

What's the timeline for accepting the fix and releasing a new build?

@dilipkrish
Copy link
Member

@tommack what was broken 2.3.1 or the PR? Probably over the weekend, haven't had a chance to test it, plus I plan to pull in swagger-ui 2.1.4.

@tommack
Copy link

tommack commented Jan 8, 2016

@dilipkrish I meant 2.3.1 was broken, haven't tested the PR.

@cm325
Copy link

cm325 commented Jan 8, 2016

im running 2.3.1 and this is broken 100% of the time

@dwtalk
Copy link

dwtalk commented Jan 8, 2016

@tommack another user here with this same issue on 2.3.2-SNAPSHOT thanks for prioritizing this weekend

@dilipkrish
Copy link
Member

Fixed via #1127

dilipkrish added a commit that referenced this issue Jan 19, 2016
@swagger420
Copy link

Hi, is the fix available?
If yes which build number please?

@dilipkrish
Copy link
Member

It will be available in 2.3.2 when its released

@vorburger
Copy link

I'm regularly hitting this one as well.. a 2.3.2 release for this alone would be neat, if you have the time.

@dilipkrish
Copy link
Member

Should be pretty soon. 👍

@bobwenx
Copy link

bobwenx commented Mar 2, 2016

@dilipkrish When will 2.4 be released?

@rzarajczyk
Copy link

Hello, I'm experiencing the same problem with 2.4.0. What data do you need to debug this problem?

@chornyi
Copy link
Contributor Author

chornyi commented Mar 18, 2016

@rzarajczyk can you please post the stack trace? Or is it exactly the one that I got last time?

@dilipkrish
Copy link
Member

@rzarajczyk I'd clean out your browser cache and try again.

@rzarajczyk
Copy link

Ok, probably it was a false alarm from my site - I updated gradle dependency of springfox to 2.4, rebuilt uding gradle and run application from IntelliJ IDEA, and the problem still exiasted. However when I run it from gradle, it begun working correctly. So maybe IntelliJ didn't refresh some content?

This brings a question by the way: is there a way to check at runtime which springfox version is used? Is it written somewhere in javascripts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants