korbit-ai[bot] commented on code in PR #34525:
URL: https://github.com/apache/superset/pull/34525#discussion_r2249630381
##########
superset/tasks/cache.py:
##########
@@ -307,25 +239,20 @@ def cache_warmup(
logger.exception(message)
return message
- results: dict[str, list[str]] = {"scheduled": [], "errors": []}
- for task in strategy.get_tasks():
- username = task["username"]
- payload = json.dumps(task["payload"])
- if username:
- try:
- user = security_manager.get_user_by_username(username)
- cookies = MachineAuthProvider.get_auth_cookies(user)
- headers = {
- "Cookie": f"session={cookies.get('session', '')}",
- "Content-Type": "application/json",
- }
- logger.info("Scheduling %s", payload)
- fetch_url.delay(payload, headers)
- results["scheduled"].append(payload)
- except SchedulingError:
- logger.exception("Error scheduling fetch_url for payload: %s",
payload)
- results["errors"].append(payload)
- else:
- logger.warn("Executor not found for %s", payload)
+ results: dict[str, list[str]] = {"success": [], "errors": []}
+
+ user = security_manager.find_user(
+ username=current_app.config["SUPERSET_CACHE_WARMUP_USER"]
+ )
+ wd = WebDriverSelenium(current_app.config["WEBDRIVER_TYPE"], user=user)
+
+ for url in strategy.get_urls():
+ try:
+ logger.info("Fetching %s", url)
+ wd.get_screenshot(url, "grid-container")
+ results["success"].append(url)
Review Comment:
### WebDriver Resource Leak <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The WebDriver instance is not being closed after use, which could lead to
resource leaks and browser processes remaining open.
###### Why this matters
Unclosed WebDriver sessions can accumulate and consume system resources,
potentially causing memory leaks and degraded system performance over time.
###### Suggested change ∙ *Feature Preview*
Implement proper WebDriver cleanup using a context manager or try-finally
block:
```python
try:
wd = WebDriverSelenium(current_app.config["WEBDRIVER_TYPE"], user=user)
for url in strategy.get_urls():
try:
logger.info("Fetching %s", url)
wd.get_screenshot(url, "grid-container")
results["success"].append(url)
except URLError:
logger.exception("Error warming up cache!")
results["errors"].append(url)
finally:
wd.quit()
```
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/116868f4-ca5b-4cb5-bc1b-f8fdd53c547a/upvote)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/116868f4-ca5b-4cb5-bc1b-f8fdd53c547a?what_not_true=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/116868f4-ca5b-4cb5-bc1b-f8fdd53c547a?what_out_of_scope=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/116868f4-ca5b-4cb5-bc1b-f8fdd53c547a?what_not_in_standard=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/116868f4-ca5b-4cb5-bc1b-f8fdd53c547a)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:328d9289-05f5-433a-8fe7-b9c75d1be1ff -->
[](328d9289-05f5-433a-8fe7-b9c75d1be1ff)
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]