You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hugegraph.apache.org by "SYaoJun (via GitHub)" <gi...@apache.org> on 2026/05/05 01:15:51 UTC
[I] [Bug] DateUtil uses shared SimpleDateFormat instances causing thread-safety issues in concurrent date parsing [hugegraph-toolchain]
SYaoJun opened a new issue, #733:
URL: https://github.com/apache/hugegraph-toolchain/issues/733
### Bug Type (问题类型)
data inconsistency (数据不一致)
### Before submit
- [x] I had searched in the [issues](https://github.com/apache/hugegraph-toolchain/issues) and found no similar issues.
### Environment (环境信息)
- Server Version: v1.x.x
- Toolchain Version: v1.x.x
- Data Size: xx vertices, xx edges <!-- (like 1000W 点, 9000W 边) -->
### Expected & Actual behavior (期望与实际表现)
# Not thread-safe
`DateUtil.parse()` and `DateUtil.now()` methods are not thread-safe. When called concurrently from multiple threads with different time zones, the time zone settings can interfere with each other, leading to incorrect parsing results.
```java
Thread A: setTimeZone("GMT+8") → Thread B: setTimeZone("GMT+0") → Thread A: parse() // uses wrong GMT+0 timezone
```
### Vertex/Edge example (问题点 / 边数据举例)
```javascript
```
### Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)
```javascript
```
--
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: issues-unsubscribe@hugegraph.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [I] [Bug] DateUtil uses shared SimpleDateFormat instances causing thread-safety issues in concurrent date parsing [hugegraph-toolchain]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #733:
URL: https://github.com/apache/hugegraph-toolchain/issues/733#issuecomment-4375833973
<!-- Greeting -->
Hi @SYaoJun! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the hugegraph-toolchain team.
<!-- Answer -->
You're correct that there's a thread-safety issue here, though with a nuance worth noting.
`DateUtil` doesn't actually use `SimpleDateFormat` directly — it uses `SafeDateFormat`, a wrapper around Joda-Time's `DateTimeFormatter` [[1]](https://github.com/apache/hugegraph/blob/9126c80e414c073b60fc074361b211cfb409e0eb/hugegraph-commons/hugegraph-common/src/main/java/org/apache/hugegraph/date/SafeDateFormat.java). However, the race condition you identified is still valid. The problem is in the `parse()` method [[2]](https://github.com/apache/hugegraph-toolchain/blob/bc49e6683fcc8f00e32d290cd558a0320c1850a3/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/util/DateUtil.java#L35-L38):
```java
public static Date parse(String source, String df, String timeZone) {
SafeDateFormat dateFormat = getDateFormat(df);
dateFormat.setTimeZone(timeZone);
return dateFormat.parse(source);
}
```
`SafeDateFormat` instances are cached in a shared `ConcurrentHashMap` keyed by format pattern [[3]](https://github.com/apache/hugegraph-toolchain/blob/bc49e6683fcc8f00e32d290cd558a0320c1850a3/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/util/DateUtil.java#L28). While `setTimeZone()` is individually synchronized in `SafeDateFormat` [[4]](https://github.com/apache/hugegraph/blob/9126c80e414c073b60fc074361b211cfb409e0eb/hugegraph-commons/hugegraph-common/src/main/java/org/apache/hugegraph/date/SafeDateFormat.java#L42-L47), the `setTimeZone()` + `parse()` sequence is **not atomic**. This means exactly the scenario you described can occur — Thread B can change the timezone between Thread A's `setTimeZone()` and `parse()` calls.
The `now()` method has a related issue: it uses whatever timezone was last set on the cached formatter, which is non-deterministic in a concurrent context [[5]](https://github.com/apache/hugegraph-toolchain/blob/bc49e6683fcc8f00e32d290cd558a0320c1850a3/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/util/DateUtil.java#L49-L51).
A fix could involve either:
1. Synchronizing the entire `setTimeZone()` + `parse()`/`format()` operation on the `SafeDateFormat` instance
2. Using `ThreadLocal<SafeDateFormat>` instances instead of a shared cache
3. Creating a new formatter per call when a non-default timezone is specified
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fhugegraph-toolchain).*
---
Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-tagline&utm_term=apache%2Fhugegraph-toolchain).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-feedback&utm_term=apache%2Fhugegraph-toolchain&message_id=c3946a63-4107-43fb-b2ef-2fab1e8d914d) [](https://github.dosu.com/apache/hugegraph-toolchain?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-repo&utm_term=apache%2Fhugegraph-toolchain) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-share-team&utm_term=apache%2Fhugegraph-toolchain)
--
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [I] [Bug] DateUtil uses shared SimpleDateFormat instances causing thread-safety issues in concurrent date parsing [hugegraph-toolchain]
Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin closed issue #733: [Bug] DateUtil uses shared SimpleDateFormat instances causing thread-safety issues in concurrent date parsing
URL: https://github.com/apache/hugegraph-toolchain/issues/733
--
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org