You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@grails.apache.org by "codeconsole (via GitHub)" <gi...@apache.org> on 2026/05/01 22:03:13 UTC
[I] 7.0.x BUG - getMimeTypes() race condition results in content getting served as xhtml and failing in safari [grails-core]
codeconsole opened a new issue, #15617:
URL: https://github.com/apache/grails-core/issues/15617
### Expected Behavior
# Grails core should not silently fall back to createDefaults() in getMimeTypes() — when there's no request,
it should defer caching, not poison it.
`org.grails.web.mime.HttpServletResponseExtension.getMimeTypes()`
```java
public static MimeType[] getMimeTypes() {
if (mimeTypes == null) { // ← static field, populated once
webRequest = GrailsWebRequest.lookup(); // ← thread-local request lookup
ApplicationContext ctx = webRequest?.getApplicationContext();
if (ctx != null) {
// CORRECT PATH: read app config via Spring
mimeTypes = ctx.getBean(MimeUtility).getKnownMimeTypes();
loadMimeTypeConfig(ctx.getBean(GrailsApplication).config);
} else {
// WRONG-FALLBACK PATH:
mimeTypes = MimeType.createDefaults(); // [XHTML, HTML, XML, ...]
}
}
return mimeTypes;
}
```
### Actual Behaviour
_No response_
### Steps To Reproduce
_No response_
### Environment Information
_No response_
### Example Application
_No response_
### Version
7.0.10
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] getMimeTypes() race condition results in content getting served as xhtml and failing in safari [grails-core]
Posted by "codeconsole (via GitHub) via notifications" <no...@grails.apache.org>.
codeconsole commented on issue #15617:
URL: https://github.com/apache/grails-core/issues/15617#issuecomment-6953151110
@hk2166 I am just wondering if it is even worth fixing since it would merge up to nowhere. We are planning on a quick release cycle to 9.0.0 before the end of the year
Are you in urgent need of the fix?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] getMimeTypes() race condition results in content getting served as xhtml and failing in safari [grails-core]
Posted by "codeconsole (via GitHub) via notifications" <no...@grails.apache.org>.
codeconsole commented on issue #15617:
URL: https://github.com/apache/grails-core/issues/15617#issuecomment-6805608744
hi @hk2166 , make sure you award of 9.x changes https://github.com/apache/grails-core/pull/16237
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] getMimeTypes() race condition results in content getting served as xhtml and failing in safari [grails-core]
Posted by "codeconsole (via GitHub) via notifications" <no...@grails.apache.org>.
codeconsole commented on issue #15617:
URL: https://github.com/apache/grails-core/issues/15617#issuecomment-6885564011
This is fixed in Grails 9 (9.0.x and 9.1.x). #16237 removed the static cache that caused it, in a1f6e39184.
On 9.0.x, `HttpServletResponseExtension.getMimeTypes()` keeps no state. It looks the types up again on every call:
```groovy
static MimeType[] getMimeTypes() {
ApplicationContext context = GrailsWebRequest.lookup()?.applicationContext
MimeUtility mimeUtility = context?.getBeanProvider(MimeUtility)?.getIfAvailable()
return mimeUtility?.knownMimeTypes as MimeType[] ?: MimeType.createDefaults()
}
```
So each part of this issue no longer applies there:
- **Defaults no longer stick.** A call made with no request bound, or with no `MimeUtility` bean, still gets `MimeType.createDefaults()`, but only for that call. Nothing is stored, so the next call made inside a request gets the application's configured `grails.mime.types`.
- **The settings are no longer skipped.** `loadMimeTypeConfig` and its static fields are gone. `GrailsContentNegotiationStrategy` reads `grails.mime.use.accept.header` and `grails.mime.disable.accept.header.userAgents` from the application config, so an early call made outside a request can no longer switch them off.
- **There is no shared field to race on.** With no cached array, threads have nothing to see half-set.
The old `if (mimeTypes == null)` cache is still on 7.0.x, 8.0.x and 8.1.x, so the bug remains on those lines. If a fix lands there, the merge-up into 9.0.x should keep 9.0.x's `getMimeTypes()` as it is, because there is no cache there to fix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] getMimeTypes() race condition results in content getting served as xhtml and failing in safari [grails-core]
Posted by "hk2166 (via GitHub) via notifications" <no...@grails.apache.org>.
hk2166 commented on issue #15617:
URL: https://github.com/apache/grails-core/issues/15617#issuecomment-6940936391
Thanks, that makes sense for 9.x. 7.0.x and 8.0.x still cache the defaults, and the issue is against 7.0.10. Would you like a small fix there (cache only the configured types, against 7.0.x, merged up to 8.0.x), or should 7.x/8.x stay as they are?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] getMimeTypes() race condition results in content getting served as xhtml and failing in safari [grails-core]
Posted by "hk2166 (via GitHub) via notifications" <no...@grails.apache.org>.
hk2166 commented on issue #15617:
URL: https://github.com/apache/grails-core/issues/15617#issuecomment-6803698329
I'd like to work on this. The code is the same on 7.0.x and 8.0.x.
`HttpServletResponseExtension.getMimeTypes()` keeps the mime types in a static field that is filled once. When the first call finds no `GrailsWebRequest`, or a context without a `MimeUtility` bean, it stores `MimeType.createDefaults()`, so every later request uses the defaults until shutdown:
- the app's configured `grails.mime.types` are ignored;
- `loadMimeTypeConfig` never runs, so the `grails.mime.disable.accept.header.userAgents` and `grails.mime.use.accept.header` settings are ignored too;
- the defaults list XHTML first, which is how content ends up served as `application/xhtml+xml`.
My plan, against 7.0.x unless you'd prefer another branch:
1. Cache only the types read from the `MimeUtility` bean. Without a context, return the defaults for that call and leave the cache empty, so the next call made inside a request reads the configured types.
2. Make the cached field safe to read from other threads, so a request never sees a half-set cache.
3. Add a spec in `grails-mimetypes`: a call with no request bound gets the defaults, and a later call within a request gets the configured types and their settings. Today the second call returns the defaults.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org