Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 11:22 PM
Steve Clark
 
Posts: n/a
Default --enable-thread-safety bug

Hello List,

I am running 8.3.1 on FreeBSD 6.2 patch-7.

The ports for Freebsd turn on --enable-thread-safety during configure
of pg.

When running my app after some time I have been getting a core dump -
sig 11.

#0 0x28333b96 in memcpy () from /lib/libc.so.6
(gdb) bt
#0 0x28333b96 in memcpy () from /lib/libc.so.6
#1 0x280d0122 in ecpg_init_sqlca (sqlca=0x0) at misc.c:100
#2 0x280d0264 in ECPGget_sqlca () at misc.c:145
#3 0x280d056c in ecpg_log (
format=0x280d1d78 "free_params line %d: parameter %d = %s\n") at
misc.c:243
#4 0x280c9758 in free_params (paramValues=0x836fe00, nParams=104,
print=1 '\001',
lineno=3303) at execute.c:1045
#5 0x280c9f08 in ecpg_execute (stmt=0xa726f00) at execute.c:1298
#6 0x280ca978 in ECPGdo (lineno=3303, compat=0, force_indicator=1,
connection_name=0x0, questionmarks=0 '\0', st=0,
query=0x806023c "update T_UNIT_STATUS_LOG set ip_address = $1
:: inet , last_ip_address = $2 :: inet , unit_date = $3 ::
timestamp with time zone , unit_raw_time = $4 , status_date = now
() , unit_ac"...) at execute.c:1636
#7 0x08057a46 in UpdateTUSL (pCachedUnit=0x807b680, msg=0xbfbf8850 "",
p_threshold=80, p_actualIP=0xbfbfe880 "24.39.85.226")
at srm2_monitor_db.pgc:3303
#8 0x0804f174 in main (argc=3, argv=0xbfbf7fc0) at
srm2_monitor_server.c:3265
(gdb) f 2
#2 0x280d0264 in ECPGget_sqlca () at misc.c:145
145 ecpg_init_sqlca(sqlca);
(gdb) p sqlca
$1 = (struct sqlca_t *) 0x0

in looking in the code in misc.c

I see:

struct sqlca_t *
ECPGget_sqlca(void)
{
#ifdef ENABLE_THREAD_SAFETY
struct sqlca_t *sqlca;

pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);

sqlca = pthread_getspecific(sqlca_key);
if (sqlca == NULL)
{
sqlca = malloc(sizeof(struct sqlca_t));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ecpg_init_sqlca(sqlca);
pthread_setspecific(sqlca_key, sqlca);
}
return (sqlca);
#else
return (&sqlca);
#endif
}

The return from malloc should be checked to make sure it succeeds -
right???

Steve

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 11:22 PM
Tom Lane
 
Posts: n/a
Default Re: --enable-thread-safety bug

Steve Clark <sclark@netwolves.com> writes:
> The return from malloc should be checked to make sure it succeeds -
> right???


Probably, but what do you expect the code to do if it doesn't succeed?
This function seems not to have any defined error-return convention.

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 11:22 PM
Steve Clark
 
Posts: n/a
Default Re: --enable-thread-safety bug

Tom Lane wrote:
> Steve Clark <sclark@netwolves.com> writes:
>
>>The return from malloc should be checked to make sure it succeeds -
>>right???

>
>
> Probably, but what do you expect the code to do if it doesn't succeed?
> This function seems not to have any defined error-return convention.
>
> regards, tom lane
>
>

Retry - the malloc - maybe there is a memory leak when
--enable-thread-saftey is enabled,
send an out of memory message to the postgres log, abort the
transaction - I don't know I am
not a postgres developer so I don't know all the issues. I all I know
as a user having a program
like postgres just sig 11 is unacceptable! As a commercial developer
of software for over 30 years
I would never just do nothing.

My $.02
Steve

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 11:22 PM
Martijn van Oosterhout
 
Posts: n/a
Default Re: --enable-thread-safety bug

On Sat, Mar 22, 2008 at 11:28:24AM -0400, Steve Clark wrote:
> Retry - the malloc - maybe there is a memory leak when
> --enable-thread-saftey is enabled,
> send an out of memory message to the postgres log, abort the
> transaction - I don't know I am
> not a postgres developer so I don't know all the issues. I all I know
> as a user having a program
> like postgres just sig 11 is unacceptable! As a commercial developer
> of software for over 30 years
> I would never just do nothing.


Note this is your in application, not the server. Only your program
died. Ofcourse the transaction got aborted, since the client (you)
disconnected. There is no way for this to write to the server log,
since it may be one another machine...

As to the issue at hand: it looks like your program ran out of memory.
Can you confirm the memory was running low? Even if it handled it by
returning NULL, the caller will die because it also needs memory.

Do you create and destroy a lot of threads since it seems this memory
won't be freed?

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFH5TN6IB7bNG8LQkwRAuTnAJ9Sz+mgeSnYuZ5572mgA3 Su7mF/VQCePKDX
t/tfBF0KQheosARKP+WZbEE=
=lyS/
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-09-2008, 11:22 PM
Tom Lane
 
Posts: n/a
Default Re: --enable-thread-safety bug

Martijn van Oosterhout <kleptog@svana.org> writes:
> Note this is your in application, not the server. Only your program
> died. Ofcourse the transaction got aborted, since the client (you)
> disconnected. There is no way for this to write to the server log,
> since it may be one another machine...


Right. And note that if we don't have enough memory for the struct
that was requested, we *certainly* don't have enough to do anything
interesting. We could try

fprintf(stderr, "out of memory\n");
exit(1);

but even that I would give only about 50-50 odds of success; and more
to the point, how is this any better for an application than a core
dump? It's still summary termination.

> Do you create and destroy a lot of threads since it seems this memory
> won't be freed?


The OP's program isn't threaded at all, since he was apparently running
with a non-threaded ecpg/libpq before. This means that the proposal of
looping till someone else frees memory is at least as silly as allowing
the core dump to happen.

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-09-2008, 11:22 PM
Steve Clark
 
Posts: n/a
Default Re: --enable-thread-safety bug

Tom Lane wrote:
> Martijn van Oosterhout <kleptog@svana.org> writes:
>
>>Note this is your in application, not the server. Only your program
>>died. Ofcourse the transaction got aborted, since the client (you)
>>disconnected. There is no way for this to write to the server log,
>>since it may be one another machine...

>
>
> Right. And note that if we don't have enough memory for the struct
> that was requested, we *certainly* don't have enough to do anything
> interesting. We could try
>
> fprintf(stderr, "out of memory\n");
> exit(1);
>
> but even that I would give only about 50-50 odds of success; and more
> to the point, how is this any better for an application than a core
> dump? It's still summary termination.
>
>
>>Do you create and destroy a lot of threads since it seems this memory
>>won't be freed?

>
>
> The OP's program isn't threaded at all, since he was apparently running
> with a non-threaded ecpg/libpq before. This means that the proposal of
> looping till someone else frees memory is at least as silly as allowing
> the core dump to happen.
>
> regards, tom lane
>
>

I guess the real question is why we are running out of memory when
this option is enabled.
Since my app doesn't use threads that points to a memory leak in the
ecpg library when enable thread
safety is turned on.


Steve

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-09-2008, 11:22 PM
Steve Clark
 
Posts: n/a
Default Re: --enable-thread-safety bug

Martijn van Oosterhout wrote:
> On Sat, Mar 22, 2008 at 11:28:24AM -0400, Steve Clark wrote:
>
>>Retry - the malloc - maybe there is a memory leak when
>>--enable-thread-saftey is enabled,
>>send an out of memory message to the postgres log, abort the
>>transaction - I don't know I am
>>not a postgres developer so I don't know all the issues. I all I know
>>as a user having a program
>>like postgres just sig 11 is unacceptable! As a commercial developer
>>of software for over 30 years
>>I would never just do nothing.

>
>
> Note this is your in application, not the server. Only your program
> died. Ofcourse the transaction got aborted, since the client (you)
> disconnected. There is no way for this to write to the server log,
> since it may be one another machine...
>
> As to the issue at hand: it looks like your program ran out of memory.
> Can you confirm the memory was running low? Even if it handled it by
> returning NULL, the caller will die because it also needs memory.
>
> Do you create and destroy a lot of threads since it seems this memory
> won't be freed?
>
> Have a nice day,

My program had no threads - as I pointed out if I change the default
Makefile in the FreeBSD ports
system to not enable thread safety my programs runs just fine for days
on end. It appears to me
without any kind of close examination that there is a memory leak in
the ecpg library when enable
thread safety is turned on.

I had an earlier problem in 8.2.6 where if enable-thread-safety was
turned on sqlca would always be zero
no matter if there was an error or not.

This appears to me to be a problem in the ecpg library when thread
safety is enabled.

Have a nice day.

Steve

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-09-2008, 11:22 PM
Michael Meskes
 
Posts: n/a
Default Re: --enable-thread-safety bug

On Sat, Mar 22, 2008 at 12:51:30PM -0400, Steve Clark wrote:
> My program had no threads - as I pointed out if I change the default
> Makefile in the FreeBSD ports
> system to not enable thread safety my programs runs just fine for days
> on end. It appears to me
> without any kind of close examination that there is a memory leak in the
> ecpg library when enable
> thread safety is turned on.


There are just a few variables covered by ENABLE_THREAD_SAFETY. I wonder
how the program manages to spend so much time allocating memory to eat
all of it. Could you give us some more info about your source code? Do
you use descriptors? Auto allocating?

Michael
--
Michael Meskes
Email: Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go VfL Borussia! Go SF 49ers! Use Debian GNU/Linux! Use PostgreSQL!

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-09-2008, 11:22 PM
Steve Clark
 
Posts: n/a
Default Re: --enable-thread-safety bug

Michael Meskes wrote:
> On Sat, Mar 22, 2008 at 12:51:30PM -0400, Steve Clark wrote:
>
>>My program had no threads - as I pointed out if I change the default
>>Makefile in the FreeBSD ports
>>system to not enable thread safety my programs runs just fine for days
>>on end. It appears to me
>>without any kind of close examination that there is a memory leak in the
>>ecpg library when enable
>>thread safety is turned on.

>
>
> There are just a few variables covered by ENABLE_THREAD_SAFETY. I wonder
> how the program manages to spend so much time allocating memory to eat
> all of it. Could you give us some more info about your source code? Do
> you use descriptors? Auto allocating?
>
> Michael


Hi Michael,

Not exactly sure what you are asking about - descriptors and auto
allocating.

The program processes about 800000 packets a day, which can update
several tables.
It runs continously reading udp packets from systems at remote
locations coming in over the internet.

It has a global
exec sql include sqlca;

then a number of functions that get called with each function having
it own

xxx( args,... )
{
EXEC SQL BEGIN DECLARE SECTION;
a bunch of variable
EXEC SQL END DECLARE SECTION;

with various EXEC SQL inserts, updates and selects.
with checks of sqlca.sqlcode to determine if the sql statement succeeded.

}

Steve

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-09-2008, 11:22 PM
Steve Clark
 
Posts: n/a
Default Re: --enable-thread-safety bug

Steve Clark wrote:
> Michael Meskes wrote:
>
>>On Sat, Mar 22, 2008 at 12:51:30PM -0400, Steve Clark wrote:
>>
>>
>>>My program had no threads - as I pointed out if I change the default
>>>Makefile in the FreeBSD ports
>>>system to not enable thread safety my programs runs just fine for days
>>>on end. It appears to me
>>>without any kind of close examination that there is a memory leak in the
>>>ecpg library when enable
>>>thread safety is turned on.

>>
>>
>>There are just a few variables covered by ENABLE_THREAD_SAFETY. I wonder
>>how the program manages to spend so much time allocating memory to eat
>>all of it. Could you give us some more info about your source code? Do
>>you use descriptors? Auto allocating?
>>
>>Michael

>
>
> Hi Michael,
>
> Not exactly sure what you are asking about - descriptors and auto
> allocating.
>
> The program processes about 800000 packets a day, which can update
> several tables.
> It runs continously reading udp packets from systems at remote
> locations coming in over the internet.
>
> It has a global
> exec sql include sqlca;
>
> then a number of functions that get called with each function having
> it own
>
> xxx( args,... )
> {
> EXEC SQL BEGIN DECLARE SECTION;
> a bunch of variable
> EXEC SQL END DECLARE SECTION;
>
> with various EXEC SQL inserts, updates and selects.
> with checks of sqlca.sqlcode to determine if the sql statement succeeded.
>
> }
>
> Steve
>

to further illustrate our code below is a typical exec sql statement:
exec sql insert into t_unit_event_log
(event_log_no,
unit_serial_no,
event_type,
event_category,
event_mesg,
event_severity,
event_status,
event_ref_log_no,
event_logged_by,
event_date,
alarm,
last_updated_by,
last_updated_date)
values (nextval('seq_event_log_no'),
:h_serial_no,
'ALERT',
:h_category,
:h_mesg,
:h_sev,
3,
NULL,
current_user,
now(),
:h_alarm,
current_user,
now());

if (sqlca.sqlcode != 0)

{
VARLOG(INFO, LOG_LEVEL_DBG4, "could not insert into
T_UNIT_EVENT_LOG\n");
VARLOG(INFO, LOG_LEVEL_DBG4, "insertTUEL returns %d\n", ret);
return ret;
}


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:46 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560