adilapapaya / rpostgresql

Automatically exported from code.google.com/p/rpostgresql
0 stars 0 forks source link

Errors and Segfaults in dbColumnInfo #42

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
For many months I've been getting intermittent errors and segfaults running 
long jobs that combine multicore (mcparallel/mclapply) and RPostgreSQL calls. 
The below code shows how to reproduce some of these problems by using gctorture 
to ferret out memory protection and connection problems. I've labelled five 
bugs below, but likely there are only one or two distinct bugs. The first three 
produce errors  for code that should likely run correctly and the last two 
segfaults.

## Bug 1. Query 'SELECT 1;' with gctorture on.
> p <- dbDriver("PostgreSQL")
> con <- dbConnect(p, host="localhost", user="user", password="pwd, 
dbname="template1")
> gctorture(TRUE)
> for (i in 1:10) dbGetQuery(con, "SELECT 1;")
Error in if (flds[[i]] == 1114) { : argument is of length zero

## Bug 2. Query column info with gctorture on.
> rs <- dbSendQuery(con, "SELECT 1;")
> gctorture(TRUE)
> for (i in 1:10) dbColumnInfo(rs)
Error in postgresqlDescribeFields(res, ...) : 
  RS-DBI driver: (internal error in RS_DBI_SclassNames: input S types must be nonNULL)

## Bug 3. Run #2 again, but inside a 'try' to expose a different error
> for (i in 1:10) try(dbColumnInfo(rs))
Error : protect(): protection stack overflow

## I think Bugs 1-3 may all be the same since they all come from dbColumnInfo 
in one manner or another.

## Bug 4. Here we use both gctorture and mclapply on a 40-column table, _xyz, 
until we get a segfault on one or more of the cores.
p <- dbDriver("PostgreSQL")
con <- dbConnect(p, host=host, user=user, password=password, dbname=dbname)
qry <- paste("CREATE TABLE _xyz (", # Create 40 column table
             paste("x", 1:40, " real", sep="", collapse=", "), ");")
dbSendQuery(con, qry)
gctorture(TRUE)
mclapply(1:16, function(x) {
    p <- dbDriver("PostgreSQL")
    con <- dbConnect(p, host=host, user=user, password=password, dbname=dbname)
    dbGetQuery(con, "SELECT * FROM _xyz limit 0;")
    dbDisconnect(con)
}, mc.cores=8)
gctorture(FALSE)

 *** caught segfault ***
address 0xfe65b88, cause 'memory not mapped'

 *** caught segfault ***
address 0xfe65b88, cause 'memory not mapped'
*** glibc detected *** /data/gentoo/usr/lib/R/bin/exec/R: double free or 
corruption (!prev): 0x000000000f490b10 ***
======= Backtrace: =========
/lib64/libc.so.6[0x377a870baf]
/lib64/libc.so.6(cfree+0x4b)[0x377a87100b]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585d03ee0]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_cons+0xda)[0x2ad585d0542a]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_allocList+0x2f)[0x2ad585d055ff]
/data/gentoo/usr/lib/R/lib/libR.so(R_GetTraceback+0x65)[0x2ad585cb3c15]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585cfd021]
/lib64/libpthread.so.0[0x377b80ebe0]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585d00c76]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585d026fd]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_cons+0xda)[0x2ad585d0542a]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_defineVar+0x274)[0x2ad585cadd14]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585ccc639]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x55b)[0x2ad585cc96eb]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585ccc790]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x55b)[0x2ad585cc96eb]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_applyClosure+0x340)[0x2ad585ccdac0]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x430)[0x2ad585cc95c0]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585ccd3b7]
/data/gentoo/usr/lib/R/lib/libR.so(R_execMethod+0x225)[0x2ad585ccd6e5]
/data/gentoo/usr/lib/R/library/methods/libs/methods.so[0x2ad588637cdb]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585d14283]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x68f)[0x2ad585cc981f]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_applyClosure+0x340)[0x2ad585ccdac0]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x430)[0x2ad585cc95c0]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585ccb2bf]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585d92e32]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x55b)[0x2ad585cc96eb]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585ccaf79]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x629)[0x2ad585cc97b9]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585ccd3b7]
/data/gentoo/usr/lib/R/lib/libR.so(R_execMethod+0x225)[0x2ad585ccd6e5]
/data/gentoo/usr/lib/R/library/methods/libs/methods.so[0x2ad588637cdb]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585d14283]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x68f)[0x2ad585cc981f]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585cc9a6b]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585cc8ae5]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x17a)[0x2ad585cc930a]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585cc9a6b]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585cc8ae5]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x17a)[0x2ad585cc930a]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_applyClosure+0x340)[0x2ad585ccdac0]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585cc5514]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x17a)[0x2ad585cc930a]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_applyClosure+0x340)[0x2ad585ccdac0]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x430)[0x2ad585cc95c0]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_applyClosure+0x340)[0x2ad585ccdac0]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x430)[0x2ad585cc95c0]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585ccc923]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x55b)[0x2ad585cc96eb]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585ccc790]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x55b)[0x2ad585cc96eb]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_applyClosure+0x340)[0x2ad585ccdac0]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x430)[0x2ad585cc95c0]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585ccd3b7]
/data/gentoo/usr/lib/R/lib/libR.so(R_execMethod+0x225)[0x2ad585ccd6e5]
/data/gentoo/usr/lib/R/library/methods/libs/methods.so[0x2ad588637cdb]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585d14283]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x68f)[0x2ad585cc981f]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_applyClosure+0x340)[0x2ad585ccdac0]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x430)[0x2ad585cc95c0]
/data/gentoo/usr/lib/R/lib/libR.so[0x2ad585ccc790]
/data/gentoo/usr/lib/R/lib/libR.so(Rf_eval+0x55b)[0x2ad585cc96eb]
======= Memory map: ========
00400000-00401000 r-xp 00
 *** caught segfault ***
address 0xfe65b88, cause 'memory not mapped'
...

## Sometimes I get this error as well
[1] "Error in postgresqlResultInfo(dbObj, ...) : \n  SET_STRING_ELT() can only 
be applied to a 'character vector', not a 'NULL'\n"

## Bug 5: Here we cause a segfault without either gctorture or mclapply... It 
just takes some patience. It helps if we have a query with lots of columns, so 
we'll make the table _xyz have 500 columns and run for several minutes:

> p <- dbDriver("PostgreSQL")
> con <- dbConnect(p, host=host, user=user, password=password, dbname=dbname)
> dbSendQuery(con, "DROP TABLE _xyz;")
> qry <- paste("CREATE TABLE _xyz (", # Create 40 column table o
             paste("x", 1:500, " real", sep="", collapse=", "), ");")
> dbSendQuery(con, qry)
> rs <- dbSendQuery(con, "SELECT * FROM _xyz limit 0;")
> while(TRUE) dbColumnInfo(rs) # This can take awhile.

Warning in postgresqlDescribeFields(res, ...) :
  RS-DBI driver warning: (unknown (10192))
Warning in postgresqlDescribeFields(res, ...) :
  RS-DBI driver warning: (unknown (12240))
Warning in postgresqlDescribeFields(res, ...) :
  RS-DBI driver warning: (unknown (0))

 *** caught segfault ***
address 0x1fd3, cause 'memory not mapped'

Traceback:
 1: postgresqlDescribeFields(res, ...)
 2: is(object, Cl)
 3: is(object, Cl)
 4: .valueClassTest(standardGeneric("dbColumnInfo"), "data.frame",     "dbColumnInfo")
 5: dbColumnInfo(rs)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

Let me know if you need any other information. These examples work similarly on 
my Mac and Linux.

Robert

> R.version
               _                            
platform       x86_64-pc-linux-gnu          
arch           x86_64                       
os             linux-gnu                    
system         x86_64, linux-gnu            
status                                      
major          2                            
minor          15.1                         
year           2012                         
month          06                           
day            22                           
svn rev        59600                        
language       R                            
version.string R version 2.15.1 (2012-06-22)
nickname       Roasted Marshmallows         

----------------
        Information on package 'RPostgreSQL'
Description:

Package:            RPostgreSQL
Version:            0.3-2
Date:               $Date: 2012-01-10 17:51:04 +0900 (Tue, 10 Jan 2012) $
Title:              R interface to the PostgreSQL database system
Author:             Joe Conway, Dirk Eddelbuettel, Tomoaki Nishiyama, Sameer 
Kumar
                    Prayaga (during 2008), Neil Tiffin
Maintainer:         Tomoaki Nishiyama <tomoakin@kenroku.kanazawa-u.ac.jp>
Packaged:           2012-03-21 19:07:56 UTC; a347549
Repository:         CRAN
Date/Publication:   2012-01-29 08:27:40
Built:              R 2.15.0; x86_64-pc-linux-gnu; 2012-06-27 20:40:32 UTC; unix

--------
PostgreSQL version 9.2.0

Original issue reported on code.google.com by rmcge...@gmail.com on 17 Sep 2012 at 6:49

GoogleCodeExporter commented 9 years ago
Thank you for reporting the bug related to dbColumnInfo().
I hope 1,2,3, and 5 is fixed with r236.

Original comment by tomoa...@kenroku.kanazawa-u.ac.jp on 4 Oct 2012 at 10:25

GoogleCodeExporter commented 9 years ago
Assumed to have been fixed

Original comment by tomoa...@kenroku.kanazawa-u.ac.jp on 25 Jun 2013 at 6:02