[CDRIVER-3904] "Falling back to malloc for counters" not managed by the logging handler Created: 08/Feb/21 Updated: 28/Oct/23 Resolved: 11/Feb/21 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | Logging |
| Affects Version/s: | 1.16.0 |
| Fix Version/s: | 1.17.5 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Fermín Galán | Assignee: | Clyde Bazile III (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I'm using the C driver in a program. I have set my own logging handler function (as described in http://mongoc.org/libmongoc/current/logging.html) to avoid printing anything in standard output (my function writes to a log file instead that standard output). However, I'm still getting this kind of warning in my programs output: 2021/02/04 22:33:32.0740: [ 6745]: WARNING: mongoc: Falling back to malloc for counters. Should I understand that kind of "Failling back to malloc for counters" warning are not managed by the logging handler and always go to standard output? Or should they and I'm doing something wrong in my program? (I have seen issue https://jira.mongodb.org/browse/CDRIVER-1504, which provides a solution to disable "Failling back to malloc for counters" warning. However, note that in my case I want these warning... but managed properly by my logging handler instead that printed in standard output) |
| Comments |
| Comment by Githook User [ 08/Apr/21 ] |
|
Author: {'name': 'Fermín Galán Márquez', 'email': 'fgalan@users.noreply.github.com', 'username': 'fgalan'}Message: |
| Comment by Githook User [ 08/Apr/21 ] |
|
Author: {'name': 'Clyde Bazile', 'email': '34226620+bazile-clyde@users.noreply.github.com', 'username': 'bazile-clyde'}Message: |
| Comment by Githook User [ 23/Mar/21 ] |
|
Author: {'name': 'Fermín Galán Márquez', 'email': 'fgalan@users.noreply.github.com', 'username': 'fgalan'}Message: |
| Comment by Githook User [ 23/Mar/21 ] |
|
Author: {'name': 'Clyde Bazile', 'email': '34226620+bazile-clyde@users.noreply.github.com', 'username': 'bazile-clyde'}Message: |
| Comment by Githook User [ 22/Feb/21 ] |
|
Author: {'name': 'Fermín Galán Márquez', 'email': 'fgalan@users.noreply.github.com', 'username': 'fgalan'}Message: |
| Comment by Fermín Galán [ 11/Feb/21 ] |
|
Tested. Problem fixed Thanks! |
| Comment by Fermín Galán [ 11/Feb/21 ] |
|
Clyde Bazile III: I will test as soon as I can and report the result in this issue. In addition, I have provided some feedback in https://github.com/mongodb/mongo-c-driver/pull/736 in the hope you find it useful. Thanks! |
| Comment by Githook User [ 11/Feb/21 ] |
|
Author: {'name': 'Clyde Bazile', 'email': '34226620+bazile-clyde@users.noreply.github.com', 'username': 'bazile-clyde'}Message: |
| Comment by Clyde Bazile III (Inactive) [ 11/Feb/21 ] |
|
https://github.com/mongodb/mongo-c-driver/pull/736 The log handler can be set before the call to mongoc_init. fermin.galanmarquez@telefonica.com that should fix the issue, but please let us know if it doesn't. The linked PR clarifies mongoc_log_set_handler can be called before mongoc_init. |
| Comment by Jeremy Mikola [ 09/Feb/21 ] |
|
AFAIK, the the destination stream is not relevant. mongoc_log_default_handler does decide to use stderr or stdout based on the log level; however, once you assign a custom log handler gLogFunc is re-assigned and the default handler is never used again (unless intentionally restored). The behavior you're seeing likely originates from mongoc_init calling _mongoc_counters_init. I'm not sure if it's possible to assign log handlers before calling mongoc_init, but that seems like that may be only way to address without internal changes to libmongoc (e.g. delaying counter initialization until users have a chance to set a custom logger). Custom Log Handlers also demonstrates calling mongoc_init before mongoc_log_set_handler. Looking at the source of mongoc_log_set_handler, it appears to only initialize a mutex and assign two globals (within a mutex lock). I don't believe that depends on anything setup by mongoc_init so you may be able to just move mongoc_log_set_handler before mongoc_init to resolve this. kevin.albertson, clyde.bazile: If that's suitable, then perhaps you can repurpose this ticket to revise the doc example in Custom Log Handlers. |
| Comment by Fermín Galán [ 09/Feb/21 ] |
|
Maybe what is happening is the "Failling back to malloc for counters" trace is sent to stderr instead of stdout but the log handler only deals with traces aimed at stdout? (Not sure, just trying to give ideas in the hope they can be useful |
| Comment by Esha Bhargava [ 08/Feb/21 ] |
|
fermin.galanmarquez@telefonica.com Thank you for reporting this issue! We'll look into it soon and get back to you. |