You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Pavel Šmejkal <pa...@tricube.cz> on 2006/08/05 15:36:11 UTC

apr_hash_get problem

Hello, I am trying to improve mod_vhost_dbi module. I added some new 
features like better PHP support and caching with apr_hash. Everything 
works fine but i have little problem with function apr_hash_get. I have 
structure vhost_cache_entry which i created and fill. there is stored 
informations about virtual host. After this i store this structure to 
hash table. In next request is this information retrieved from hash 
table instead of  database. But some times function apr_hash_get returns 
damaged structure with string like "\xf06\xc5" in document_root 
property. I can find any thing wrong in my code. In next request is 
everything ok. Is there somebody which can helps me please.

// CREATE CACHE_ENTRY
cache_entry = (vhost_cache_entry *) apr_pcalloc(r->pool, 
sizeof(vhost_cache_entry));

// GET STRUCTURE
cache_entry = apr_hash_get(vhost_cache, host, APR_HASH_KEY_STRING);


// STORE STRUCTURE
apr_hash_set(vhost_cache, host, APR_HASH_KEY_STRING, cache_entry);


// STRUCTURES
typedef struct
{
    /* Is Vhost Dbi on or off? */
    int status;
    /* IS PHP SafeMod on or off? */
    int safe_mode;
    /* String Identifier of our DBI Connection Pool */
    conn_id id;
    /* SQL Query to use for finding the Virtual Host Information */
    const char *document_root;
    const char *server_name;
    const char *username;
    const char *query;
    const char *append_to_open_base_dir;
} vhost_dbi_config_rec;

typedef struct
{
    const char name;
    vhost_dbi_config_rec rec;
} vhost_cache_entry;



Re: apr_hash_get problem

Posted by Pavel Šmejkal <pa...@tricube.cz>.
At a guess, I would guess the cache structure or some of the fields are 
being allocated out of a per-request pool, and that pool gets cleared 
before the next request.
>> // CREATE CACHE_ENTRY
>> cache_entry = (vhost_cache_entry *) apr_pcalloc(r->pool, 
>> sizeof(vhost_cache_entry));

I changed code to "cache_entry = (vhost_cache_entry *) 
apr_pcalloc(r->server->process->pool, sizeof(vhost_cache_entry));" but 
it looks like worst than before.
Maybe it is because i create this hash in pre_config fce:

static apr_status_t vhost_dbi_pre_config(apr_pool_t * pconf, apr_pool_t 
* plog, apr_pool_t * ptemp) {
    apr_status_t rv = APR_SUCCESS;
    vhost_cache = apr_hash_make(pconf);
    return rv;
}

It is very strange behavior because a few request is ok and after this 
one request retrieved damaged structure form hashtable. Structure 
contains some uppredictable data ... some chars from memory maybe, piece 
url or is completely empty. Maybe some thread stuffs ? ... is 
apr_hashtable thread safe ? according to logs every thinks looks like 
perfect ... cache expire etc ... but some times stucture lose its data...

Thanks for your help ... i can't find some suitable maillist :( ,

P.



 

Re: apr_hash_get problem

Posted by Paul Querna <ch...@force-elite.com>.
Pavel Šmejkal wrote:
> Hello, I am trying to improve mod_vhost_dbi module.

Off topic for this list, but I am the author of this module, and if you 
are interested, I am willing to give commit access to it or get your 
patches into the 'official' version.

> I added some new 
> features like better PHP support and caching with apr_hash. Everything 
> works fine but i have little problem with function apr_hash_get. I have 
> structure vhost_cache_entry which i created and fill. there is stored 
> informations about virtual host. After this i store this structure to 
> hash table. In next request is this information retrieved from hash 
> table instead of  database. But some times function apr_hash_get returns 
> damaged structure with string like "\xf06\xc5" in document_root 
> property. I can find any thing wrong in my code. In next request is 
> everything ok. Is there somebody which can helps me please.

At a guess, I would guess the cache structure or some of the fields are 
being allocated out of a per-request pool, and that pool gets cleared 
before the next request.

> // CREATE CACHE_ENTRY
> cache_entry = (vhost_cache_entry *) apr_pcalloc(r->pool, 
> sizeof(vhost_cache_entry));

Yep, you shouldn't use r->pool for this.  The lifetime for r->pool is 
just for this request, consider using r->server->process->pool.


-Paul