Opened 12 years ago

Closed 12 years ago

#138 closed defect (fixed)

Does ngx_mutex_init have an error?

Reported by: Vincent Lee Owned by: somebody
Priority: minor Milestone:
Component: other Version: 1.1.x
Keywords: ngx_mutex_init Cc: win32
uname -a: win32
nginx -V: nginx version: nginx/1.1.16

Description

.\nginx\src\os\win32\ngx_thread.c
#if (NGX_THREADS)
ngx_mutex_t *ngx_event_timer_mutex; this ngx_event_timer_mutex is a pointer.
#endif

ngx_mutex_t *
ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags)
{

return (ngx_mutex_t *) 1;convert 1 to "ngx_mutex_t *" ???

}

ngx_int_t
ngx_event_timer_init(ngx_log_t *log)
{

ngx_rbtree_init(&ngx_event_timer_rbtree, &ngx_event_timer_sentinel,

ngx_rbtree_insert_timer_value);

#if (NGX_THREADS)

if (ngx_event_timer_mutex) { ngx_event_timer_mutex is 1

ngx_event_timer_mutex->log = log;here will be error...
return NGX_OK;

}

ngx_event_timer_mutex = ngx_mutex_init(log, 0);
if (ngx_event_timer_mutex == NULL) {

return NGX_ERROR;

}

#endif

return NGX_OK;

}

as you see, ngx_mutex_init converts 1 to a "ngx_mutex_t *" pointer, and if we do "ngx_event_timer_mutex->log = log;", it will tigger errors.

Change History (7)

comment:1 by Maxim Dounin, 12 years ago

Resolution: invalid
Status: newclosed

The ngx_event_timer_init() is only called once on process startup, and this will never happen under win32 as there is no fork() there and ngx_event_timer_mutex is always NULL on ngx_event_timer_init() call.

comment:2 by Vincent Lee, 12 years ago

yes, if master_process is on, the ngx_event_timer_init() is only called once on process startup. but if master_process is off,of course it's maybe in the devoloping process... the ngx_event_timer_init() will be called more than once.call stack likes below:
1.
nginx_vc9.exe!ngx_event_timer_init(ngx_log_s * log=0x009565bc) line31 C
nginx_vc9.exe!ngx_event_process_init(ngx_cycle_s * cycle=0x009565b0) line607 + 0xc bytes C
nginx_vc9.exe!ngx_single_process_cycle(ngx_cycle_s * cycle=0x009565b0) line1039 + 0x15 bytes C
nginx_vc9.exe!main(int argc=1, char * const * argv=0x00a32540) line409 + 0x9 bytes C
nginx_vc9.exe__tmainCRTStartup() line266 + 0x19 bytes C
nginx_vc9.exe!mainCRTStartup() line182 C
2.
nginx_vc9.exe!ngx_event_timer_init(ngx_log_s * log=0x009565bc) line31 C
nginx_vc9.exe!ngx_event_process_init(ngx_cycle_s * cycle=0x009565b0) line607 + 0xc bytes C
nginx_vc9.exe!ngx_worker_thread(void * data=0x00000000) line810 + 0x15 bytes C

this case will happen when we set master_process to be off on win32. so it's better to remove this hidden trouble.

in reply to:  1 comment:3 by Vincent Lee, 12 years ago

Replying to Maxim Dounin:

The ngx_event_timer_init() is only called once on process startup, and this will never happen under win32 as there is no fork() there and ngx_event_timer_mutex is always NULL on ngx_event_timer_init() call.

yes, if master_process is on, the ngx_event_timer_init() is only called once on process startup. but if master_process is off,of course it's maybe in the devoloping process... the ngx_event_timer_init() will be called more than once.
please see comment2 to get more details.

comment:4 by Maxim Dounin, 12 years ago

Resolution: invalid
Status: closedreopened

Ok, I see, thanks.

comment:5 by Maxim Dounin, 12 years ago

Status: reopenedaccepted

comment:6 by Maxim Dounin, 12 years ago

In [4572/nginx]:

(The changeset message doesn't reference this ticket)

comment:7 by Maxim Dounin, 12 years ago

Resolution: fixed
Status: acceptedclosed

Fix committed, thanks.

Note: See TracTickets for help on using tickets.