Alvaro Herrera wrote: > Dmitriy wrote: > > > in sql console: > > postgres=# select uuid_nil(); > > server closed the connection unexpectedly > > This probably means the server terminated abnormally > > before or while processing the request. > > Thanks for the report. I think the problem here is that we're not > checking the return values of uuid functions. For example uuid_create > could fail due to memory shortage or a number of other problems.
Please try the attached patch. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Index: contrib/uuid-ossp/uuid-ossp.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/contrib/uuid-ossp/uuid-ossp.c,v retrieving revision 1.5 diff -c -p -r1.5 uuid-ossp.c *** contrib/uuid-ossp/uuid-ossp.c 15 Nov 2007 22:25:14 -0000 1.5 --- contrib/uuid-ossp/uuid-ossp.c 27 Dec 2007 14:04:26 -0000 *************** PG_FUNCTION_INFO_V1(uuid_generate_v3); *** 64,69 **** --- 64,81 ---- PG_FUNCTION_INFO_V1(uuid_generate_v4); PG_FUNCTION_INFO_V1(uuid_generate_v5); + static void + pguuid_complain(uuid_rc_t rc) + { + char *err = uuid_error(rc); + + if (err != NULL) + ereport(ERROR, + (errmsg("uuid_export() failed: %s", err))); + else + ereport(ERROR, + (errmsg("uuid_export() failed: error code %d", rc))); + } static char * uuid_to_string(const uuid_t * uuid) *************** uuid_to_string(const uuid_t * uuid) *** 71,78 **** char *buf = palloc(UUID_LEN_STR + 1); void *ptr = buf; size_t len = UUID_LEN_STR + 1; ! uuid_export(uuid, UUID_FMT_STR, &ptr, &len); return buf; } --- 83,93 ---- char *buf = palloc(UUID_LEN_STR + 1); void *ptr = buf; size_t len = UUID_LEN_STR + 1; + uuid_rc_t rc; ! rc = uuid_export(uuid, UUID_FMT_STR, &ptr, &len); ! if (rc != UUID_RC_OK) ! pguuid_complain(rc); return buf; } *************** uuid_to_string(const uuid_t * uuid) *** 81,87 **** static void string_to_uuid(const char *str, uuid_t * uuid) { ! uuid_import(uuid, UUID_FMT_STR, str, UUID_LEN_STR + 1); } --- 96,106 ---- static void string_to_uuid(const char *str, uuid_t * uuid) { ! uuid_rc_t rc; ! ! rc = uuid_import(uuid, UUID_FMT_STR, str, UUID_LEN_STR + 1); ! if (rc != UUID_RC_OK) ! pguuid_complain(rc); } *************** special_uuid_value(const char *name) *** 90,100 **** { uuid_t *uuid; char *str; ! uuid_create(&uuid); ! uuid_load(uuid, name); str = uuid_to_string(uuid); ! uuid_destroy(uuid); return DirectFunctionCall1(uuid_in, CStringGetDatum(str)); } --- 109,126 ---- { uuid_t *uuid; char *str; + uuid_rc_t rc; ! rc = uuid_create(&uuid); ! if (rc != UUID_RC_OK) ! pguuid_complain(rc); ! rc = uuid_load(uuid, name); ! if (rc != UUID_RC_OK) ! pguuid_complain(rc); str = uuid_to_string(uuid); ! rc = uuid_destroy(uuid); ! if (rc != UUID_RC_OK) ! pguuid_complain(rc); return DirectFunctionCall1(uuid_in, CStringGetDatum(str)); } *************** uuid_generate_internal(int mode, const u *** 140,150 **** { uuid_t *uuid; char *str; ! uuid_create(&uuid); ! uuid_make(uuid, mode, ns, name); str = uuid_to_string(uuid); ! uuid_destroy(uuid); return DirectFunctionCall1(uuid_in, CStringGetDatum(str)); } --- 166,183 ---- { uuid_t *uuid; char *str; + uuid_rc_t rc; ! rc = uuid_create(&uuid); ! if (rc != UUID_RC_OK) ! pguuid_complain(rc); ! rc = uuid_make(uuid, mode, ns, name); ! if (rc != UUID_RC_OK) ! pguuid_complain(rc); str = uuid_to_string(uuid); ! rc = uuid_destroy(uuid); ! if (rc != UUID_RC_OK) ! pguuid_complain(rc); return DirectFunctionCall1(uuid_in, CStringGetDatum(str)); } *************** uuid_generate_v35_internal(int mode, pg_ *** 169,176 **** { uuid_t *ns_uuid; Datum result; ! uuid_create(&ns_uuid); string_to_uuid(DatumGetCString(DirectFunctionCall1(uuid_out, UUIDPGetDatum(ns))), ns_uuid); --- 202,212 ---- { uuid_t *ns_uuid; Datum result; + uuid_rc_t rc; ! rc = uuid_create(&ns_uuid); ! if (rc != UUID_RC_OK) ! pguuid_complain(rc); string_to_uuid(DatumGetCString(DirectFunctionCall1(uuid_out, UUIDPGetDatum(ns))), ns_uuid); *************** uuid_generate_v35_internal(int mode, pg_ *** 178,184 **** ns_uuid, DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(name)))); ! uuid_destroy(ns_uuid); return result; } --- 214,222 ---- ns_uuid, DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(name)))); ! rc = uuid_destroy(ns_uuid); ! if (rc != UUID_RC_OK) ! pguuid_complain(rc); return result; }
---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings