Service manager returning wrong instance?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Service manager returning wrong instance?

demiankatz

I’m running into an extremely strange bug using ZF 2.2.1 and PHP 5.3.6.

 

To make a long story short, under a very specific set of circumstances, Zend\ServiceManager\ServiceManager seems to be corrupting its instances property.

 

I ran into a bug where I was getting the wrong object returned by a ->get() call, and after a bit of code tracing, I determined that the wrong object was coming from the ServiceManager’s instances array…

 

I added some debug output to ServiceManager, so every place that sets a value into instances dumps out:

 

echo 'setting ' . $cName . ' to ' . (is_object($instance) ? get_class($instance) : 'non-object') . '<br />';

 

…and everything retrieving from the array dumps out:

 

echo 'returning ' . get_class($this->instances[$cName]) . ' for ' . $cName . "<br />";

 

For the offending service, my output contains:

 

setting resource to VuFind\Db\Table\Resource

returning VuFind\Record\Loader for resource

 

There is no reference to the resource service in between!  So how is it changing class?  There is no code outside of ServiceManager that manipulates instances, and I made the property private to rule out subclass interference.  Same results!

 

I can’t reproduce this problem on a different server running a newer version of PHP, so I’m suspicious that it’s some kind of crazy PHP internal problem…  but I thought I’d mention the situation here before I start upgrading PHP in desperation, just in case it rings a bell!  Anyone else seen anything like this?  Am I overlooking something important in the way SM works?

 

thanks,

Demian

Reply | Threaded
Open this post in threaded view
|

Re: Service manager returning wrong instance?

Marco Pivetta
Can you make a gist of what the issue is? I honestly didn't understand what is going on...



On 6 August 2013 21:09, Demian Katz <[hidden email]> wrote:

I’m running into an extremely strange bug using ZF 2.2.1 and PHP 5.3.6.

 

To make a long story short, under a very specific set of circumstances, Zend\ServiceManager\ServiceManager seems to be corrupting its instances property.

 

I ran into a bug where I was getting the wrong object returned by a ->get() call, and after a bit of code tracing, I determined that the wrong object was coming from the ServiceManager’s instances array…

 

I added some debug output to ServiceManager, so every place that sets a value into instances dumps out:

 

echo 'setting ' . $cName . ' to ' . (is_object($instance) ? get_class($instance) : 'non-object') . '<br />';

 

…and everything retrieving from the array dumps out:

 

echo 'returning ' . get_class($this->instances[$cName]) . ' for ' . $cName . "<br />";

 

For the offending service, my output contains:

 

setting resource to VuFind\Db\Table\Resource

returning VuFind\Record\Loader for resource

 

There is no reference to the resource service in between!  So how is it changing class?  There is no code outside of ServiceManager that manipulates instances, and I made the property private to rule out subclass interference.  Same results!

 

I can’t reproduce this problem on a different server running a newer version of PHP, so I’m suspicious that it’s some kind of crazy PHP internal problem…  but I thought I’d mention the situation here before I start upgrading PHP in desperation, just in case it rings a bell!  Anyone else seen anything like this?  Am I overlooking something important in the way SM works?

 

thanks,

Demian


Reply | Threaded
Open this post in threaded view
|

RE: Service manager returning wrong instance?

demiankatz

Unfortunately, right now the setup I need to reproduce the bug is so complicated that I’m not sure how to reduce it to a simpler case – any advice on how to narrow this down would be welcome (the problem boils down to one object getting set to $this->instances[$cName] and a different object getting returned with no apparent resetting in between…  but that makes so little sense that I’m not sure how to even analyze what’s going on!)

 

- Demian

 

From: Marco Pivetta [mailto:[hidden email]]
Sent: Tuesday, August 06, 2013 3:12 PM
To: Demian Katz
Cc: [hidden email]
Subject: Re: [zf-contributors] Service manager returning wrong instance?

 

Can you make a gist of what the issue is? I honestly didn't understand what is going on...


 

On 6 August 2013 21:09, Demian Katz <[hidden email]> wrote:

I’m running into an extremely strange bug using ZF 2.2.1 and PHP 5.3.6.

 

To make a long story short, under a very specific set of circumstances, Zend\ServiceManager\ServiceManager seems to be corrupting its instances property.

 

I ran into a bug where I was getting the wrong object returned by a ->get() call, and after a bit of code tracing, I determined that the wrong object was coming from the ServiceManager’s instances array…

 

I added some debug output to ServiceManager, so every place that sets a value into instances dumps out:

 

echo 'setting ' . $cName . ' to ' . (is_object($instance) ? get_class($instance) : 'non-object') . '<br />';

 

…and everything retrieving from the array dumps out:

 

echo 'returning ' . get_class($this->instances[$cName]) . ' for ' . $cName . "<br />";

 

For the offending service, my output contains:

 

setting resource to VuFind\Db\Table\Resource

returning VuFind\Record\Loader for resource

 

There is no reference to the resource service in between!  So how is it changing class?  There is no code outside of ServiceManager that manipulates instances, and I made the property private to rule out subclass interference.  Same results!

 

I can’t reproduce this problem on a different server running a newer version of PHP, so I’m suspicious that it’s some kind of crazy PHP internal problem…  but I thought I’d mention the situation here before I start upgrading PHP in desperation, just in case it rings a bell!  Anyone else seen anything like this?  Am I overlooking something important in the way SM works?

 

thanks,

Demian

 

Reply | Threaded
Open this post in threaded view
|

RE: Service manager returning wrong instance? (solution: don't use PHP 5.3.6)

demiankatz
In reply to this post by Marco Pivetta

A quick update:

 

Since this was so difficult to track down, I decided to try upgrading PHP to see if my theory of a low-level problem was correct.  Sure enough, moving from PHP 5.3.6 to PHP 5.3.27 solved the problem.  I wish I could provide more information to explain what was going on, but the best I can say is that a large application with multiple service managers seems prone to problems with PHP 5.3.6 – in addition to the bizarre behavior I described, I was also seeing intermittent segmentation faults.

 

- Demian

 

From: Demian Katz
Sent: Tuesday, August 06, 2013 3:39 PM
To: 'Marco Pivetta'
Cc: [hidden email]
Subject: RE: [zf-contributors] Service manager returning wrong instance?

 

Unfortunately, right now the setup I need to reproduce the bug is so complicated that I’m not sure how to reduce it to a simpler case – any advice on how to narrow this down would be welcome (the problem boils down to one object getting set to $this->instances[$cName] and a different object getting returned with no apparent resetting in between…  but that makes so little sense that I’m not sure how to even analyze what’s going on!)

 

- Demian

 

From: Marco Pivetta [mailto:[hidden email]]
Sent: Tuesday, August 06, 2013 3:12 PM
To: Demian Katz
Cc: [hidden email]
Subject: Re: [zf-contributors] Service manager returning wrong instance?

 

Can you make a gist of what the issue is? I honestly didn't understand what is going on...


 

On 6 August 2013 21:09, Demian Katz <[hidden email]> wrote:

I’m running into an extremely strange bug using ZF 2.2.1 and PHP 5.3.6.

 

To make a long story short, under a very specific set of circumstances, Zend\ServiceManager\ServiceManager seems to be corrupting its instances property.

 

I ran into a bug where I was getting the wrong object returned by a ->get() call, and after a bit of code tracing, I determined that the wrong object was coming from the ServiceManager’s instances array…

 

I added some debug output to ServiceManager, so every place that sets a value into instances dumps out:

 

echo 'setting ' . $cName . ' to ' . (is_object($instance) ? get_class($instance) : 'non-object') . '<br />';

 

…and everything retrieving from the array dumps out:

 

echo 'returning ' . get_class($this->instances[$cName]) . ' for ' . $cName . "<br />";

 

For the offending service, my output contains:

 

setting resource to VuFind\Db\Table\Resource

returning VuFind\Record\Loader for resource

 

There is no reference to the resource service in between!  So how is it changing class?  There is no code outside of ServiceManager that manipulates instances, and I made the property private to rule out subclass interference.  Same results!

 

I can’t reproduce this problem on a different server running a newer version of PHP, so I’m suspicious that it’s some kind of crazy PHP internal problem…  but I thought I’d mention the situation here before I start upgrading PHP in desperation, just in case it rings a bell!  Anyone else seen anything like this?  Am I overlooking something important in the way SM works?

 

thanks,

Demian