segfault: address (nil), cause 'memory not mapped'

912 views
Skip to first unread message

David Andel

unread,
May 28, 2014, 8:32:09 AM5/28/14
to rpostgr...@googlegroups.com
Hi

I have hit a bug which has been reported end of January with no reaction so far: http://code.google.com/p/rpostgresql/issues/detail?id=60

The simplest way to reproduce this bug I have found:

> test <- as.data.frame(do.call(rbind, list(list("A"))))
> dbWriteTable(pgcon, "test", test)

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
 1: .Call("RS_PostgreSQL_CopyInDataframe", conId, dataframe, nrow,     p, PACKAGE = .PostgreSQLPkgName)
 2: postgresqlCopyInDataframe(new.con, value)
 3: postgresqlWriteTable(conn, name, value, ...)
 4: is(object, Cl)
 5: is(object, Cl)
 6: .valueClassTest(standardGeneric("dbWriteTable"), "logical", "dbWriteTable")
 7: dbWriteTable(pgcon, "test", test)

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

When there is a table "test" in the DB, the output is as follows:
> dbWriteTable(pgcon, "test", test)
[1] FALSE
Warning message:
In postgresqlWriteTable(conn, name, value, ...) :
  table test exists in database: aborting assignTable
> dbRemoveTable(pgcon, test)
Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘dbRemoveTable’ for signature ‘"PostgreSQLConnection", "data.frame"’
> dbRemoveTable(pgcon, "test")
[1] TRUE

I am running Ubuntu 14.04 trusty with the R packages from CRAN for trusty.

David

David Andel

unread,
May 28, 2014, 8:39:10 AM5/28/14
to rpostgr...@googlegroups.com
Please ignore the last two dbRemoveTable at the end of the message. Forgot to delete them.

NISHIYAMA Tomoaki

unread,
May 28, 2014, 9:32:48 AM5/28/14
to rpostgr...@googlegroups.com, NISHIYAMA Tomoaki
Dear David,

Sorry not to have responded to the issue.
I tested your example now and it appears that segfault happen only
on some old revisions.
There were a bit of change between Jan 29 and Feb 15.
https://code.google.com/p/rpostgresql/source/list
But, it includes some work related to bytea.

Below is the transcript log with the latest.

dbWriteTable does not write the bytea value, but does not segfault.
Some tiny example to INSERT and SELECT serialized data
is present in exttests/bytea.R or RPostgreSQL/test/bytea.R
The organization of test structure is the current hurdle for next release.

> library(RPostgreSQL)
Loading required package: DBI
> con<-dbConnect("PostgreSQL")
> dbGetQuery(con,"drop table byteatable")
NULL
> dbGetQuery(con,"CREATE TABLE byteatable (name text NOT NULL, val bytea, PRIMARY KEY (name))")
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "byteatable_pkey" for table "byteatable"
NULL
> sample.object <- list("one","two");
> ser <- serialize(sample.object,NULL,ascii=F);
>
> df <- data.frame(name=c("first","second"),stringsAsFactors=F);
> df$val <- list(ser,ser)
>
> dbWriteTable(con,"byteatable",df,append=T,row.names=F)
[1] TRUE
> dbGetQuery(con,"select * from byteatable")
name val
1 first
2 second
> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] RPostgreSQL_0.5-1 DBI_0.2-7

Would you mind testing with r272?

Kind regards,
Tomoaki
> --
> You received this message because you are subscribed to the Google Groups "RPostgreSQL Development and Discussion List" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rpostgresql-d...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

NISHIYAMA Tomoaki

unread,
May 28, 2014, 10:18:13 AM5/28/14
to rpostgr...@googlegroups.com, NISHIYAMA Tomoaki
Hi,

> The simplest way to reproduce this bug I have found:
>
> > test <- as.data.frame(do.call(rbind, list(list("A"))))
> > dbWriteTable(pgcon, "test", test)

For this case again, there is no segfault but the data is not transferred.
That is the "list" datatype is not supported.
When the class is set to character, you can write the content.

> con<-dbConnect("PostgreSQL")
> test <- as.data.frame(do.call(rbind, list(list("A"))))
> dbWriteTable(con, "test", test)
[1] TRUE
> test
V1
1 A
> dbReadTable(con, "test")
V1
1
> show(test)
V1
1 A
> class(test)
[1] "data.frame"
> class(test$V1)
[1] "list"
> class(test$V1) <- "character"
> dbRemoveTable(con, "test")
[1] TRUE
> dbWriteTable(con, "test", test)
[1] TRUE
> dbReadTable(con, "test")
V1
1 A

On 2014/05/28, at 21:32, David Andel wrote:

David Andel

unread,
May 29, 2014, 8:44:44 AM5/29/14
to rpostgr...@googlegroups.com, NISHIYAMA Tomoaki
Perfect, thanks! This helped me a lot. Now I can work with the tables I get from the web.
I will not manage currently to test with another version, I am afraid.

On Wednesday, 28 May 2014 16:18:13 UTC+2, Tomoaki wrote:
> class(test$V1) <- "character"
Reply all
Reply to author
Forward
0 new messages